bbcodelib 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-09-29
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bbcodelib.gemspec
6
+ ext/Makefile
7
+ ext/bbcode.cpp
8
+ ext/bbcode_config.h
9
+ ext/bbcode_lexer.cpp
10
+ ext/bbcode_lexer.h
11
+ ext/bbcode_parser.cpp
12
+ ext/bbcode_parser.h
13
+ ext/bbcode_utils.cpp
14
+ ext/bbcode_utils.h
15
+ ext/extconf.rb
16
+ lib/bbcodelib.rb
17
+ script/console
18
+ script/destroy
19
+ script/generate
20
+ test/test_bbcodelib.rb
21
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = BBCodelib Ruby Bindings
2
+
3
+ * http://rubyforge.org/projects/bbcodelib/
4
+
5
+ == Details
6
+ This is a ruby wrapper for the bbcodelib project at source forge written by
7
+ Igor Franchuk, sprog@online.ru and available at http://sourceforge.net/projects/bbcodelib/
8
+
9
+
10
+ == To Install:
11
+
12
+ gem install bbcodelib
13
+
14
+
15
+ == To Use:
16
+
17
+ require 'rubygems'
18
+ require 'bbcode'
19
+ parsed_string = BBCode::parse_string(original_text)
20
+
21
+
22
+ If you wish to change the supported tags/output you'll need to edit bbcode_config.h and
23
+ recompile the Gem.
24
+
25
+ == License - GPL
26
+
27
+ This program is free software: you can redistribute it and/or modify
28
+ it under the terms of the GNU General Public License as published by
29
+ the Free Software Foundation, either version 3 of the License, or
30
+ (at your option) any later version.
31
+
32
+ This program is distributed in the hope that it will be useful,
33
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
34
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35
+ GNU General Public License for more details.
36
+
37
+ You should have received a copy of the GNU General Public License
38
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
39
+
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/bbcodelib'
6
+
7
+
8
+
9
+ Hoe.plugin :newgem
10
+ EXT = "lib/bbcodelib/bbcode.*"
11
+
12
+ # Generate all the Rake tasks
13
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
14
+ $hoe = Hoe.spec 'bbcodelib' do
15
+ self.developer 'Stephen Blackstone', 'sblackstone@gmail.com'
16
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
17
+ self.rubyforge_name = self.name # TODO this is default value
18
+ self.description = "Provides a fast, efficent BBcode parser for ruby via the bbcodelib package at sourceforge"
19
+ self.summary = "A ruby binding for the bbcodelib library (sourceforge)"
20
+ self.spec_extras[:extensions] = "ext/extconf.rb"
21
+ end
22
+
23
+ require 'newgem/tasks'
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ task :test => EXT
27
+
28
+ file EXT => ["ext/extconf.rb"] do # 4
29
+ Dir.chdir "ext" do
30
+ ruby "extconf.rb"
31
+ sh "make"
32
+ sh "cp bbcodelib.{so,bundle} ../lib/bbcodelib"
33
+ end
34
+ end
data/bbcodelib.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{bbcodelib}
5
+ s.version = "1.0.0"
6
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
7
+ s.authors = ["Stephen Blackstone"]
8
+ s.date = %q{2009-09-29}
9
+ s.description = %q{Provides a fast, efficent BBcode parser for ruby via the bbcodelib package at sourceforge.}
10
+ s.email = ["sblackstone@gmail.com"]
11
+ s.extensions = ["ext/extconf.rb"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "bbcodelib.gemspec", "ext/Makefile", "ext/bbcode.cpp", "ext/bbcode_config.h", "ext/bbcode_lexer.cpp", "ext/bbcode_lexer.h", "ext/bbcode_parser.cpp", "ext/bbcode_parser.h", "ext/bbcode_utils.cpp", "ext/bbcode_utils.h", "ext/extconf.rb", "lib/bbcodelib.rb", "script/console", "script/destroy", "script/generate", "test/test_bbcodelib.rb", "test/test_helper.rb"]
14
+ s.homepage = %q{http://rubyforge.org/projects/bbcodelib/}
15
+ s.post_install_message = %q{PostInstall.txt}
16
+ s.require_paths = ["lib", "ext"]
17
+ s.rubyforge_project = %q{bbcodelib}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{A ruby binding for the bbcodelib library (sourceforge)}
20
+ s.test_files = ["test/test_bbcodelib.rb", "test/test_helper.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
28
+ else
29
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
33
+ end
34
+ end
data/ext/Makefile ADDED
@@ -0,0 +1,150 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
11
+ exec_prefix = $(prefix)
12
+ sitedir = $(DESTDIR)/Library/Ruby/Site
13
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
14
+ docdir = $(datarootdir)/doc/$(PACKAGE)
15
+ dvidir = $(docdir)
16
+ datarootdir = $(prefix)/share
17
+ archdir = $(rubylibdir)/$(arch)
18
+ sbindir = $(exec_prefix)/sbin
19
+ psdir = $(docdir)
20
+ localedir = $(datarootdir)/locale
21
+ htmldir = $(docdir)
22
+ datadir = $(datarootdir)
23
+ includedir = $(prefix)/include
24
+ infodir = $(DESTDIR)/usr/share/info
25
+ sysconfdir = $(prefix)/etc
26
+ mandir = $(DESTDIR)/usr/share/man
27
+ libdir = $(exec_prefix)/lib
28
+ sharedstatedir = $(prefix)/com
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ pdfdir = $(docdir)
31
+ sitearchdir = $(sitelibdir)/$(sitearch)
32
+ bindir = $(exec_prefix)/bin
33
+ localstatedir = $(prefix)/var
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ libexecdir = $(exec_prefix)/libexec
36
+
37
+ CC = gcc
38
+ LIBRUBY = $(LIBRUBY_SO)
39
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
41
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
42
+
43
+ RUBY_EXTCONF_H =
44
+ CFLAGS = -fno-common -arch ppc -Os -pipe -fno-common
45
+ INCFLAGS = -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I.
46
+ DEFS =
47
+ CPPFLAGS =
48
+ CXXFLAGS = $(CFLAGS)
49
+ DLDFLAGS = -L. -arch ppc
50
+ LDSHARED = cc -arch ppc -pipe -bundle -undefined dynamic_lookup
51
+ AR = ar
52
+ EXEEXT =
53
+
54
+ RUBY_INSTALL_NAME = ruby
55
+ RUBY_SO_NAME = ruby
56
+ arch = universal-darwin9.0
57
+ sitearch = universal-darwin9.0
58
+ ruby_version = 1.8
59
+ ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
60
+ RUBY = $(ruby)
61
+ RM = rm -f
62
+ MAKEDIRS = mkdir -p
63
+ INSTALL = /usr/bin/install -c
64
+ INSTALL_PROG = $(INSTALL) -m 0755
65
+ INSTALL_DATA = $(INSTALL) -m 644
66
+ COPY = cp
67
+
68
+ #### End of system configuration section. ####
69
+
70
+ preload =
71
+
72
+ libpath = . $(libdir)
73
+ LIBPATH = -L. -L$(libdir)
74
+ DEFFILE =
75
+
76
+ CLEANFILES = mkmf.log
77
+ DISTCLEANFILES =
78
+
79
+ extout =
80
+ extout_prefix =
81
+ target_prefix =
82
+ LOCAL_LIBS =
83
+ LIBS = $(LIBRUBYARG_SHARED) -lstdc++ -lpthread -ldl -lm
84
+ SRCS = bbcode.cpp bbcode_lexer.cpp bbcode_parser.cpp bbcode_utils.cpp
85
+ OBJS = bbcode.o bbcode_lexer.o bbcode_parser.o bbcode_utils.o
86
+ TARGET = bbcode
87
+ DLLIB = $(TARGET).bundle
88
+ EXTSTATIC =
89
+ STATIC_LIB =
90
+
91
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
92
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
93
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
94
+
95
+ TARGET_SO = $(DLLIB)
96
+ CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
97
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
98
+
99
+ all: $(DLLIB)
100
+ static: $(STATIC_LIB)
101
+
102
+ clean:
103
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
104
+
105
+ distclean: clean
106
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
107
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
108
+
109
+ realclean: distclean
110
+ install: install-so install-rb
111
+
112
+ install-so: $(RUBYARCHDIR)
113
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
114
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
115
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
116
+ install-rb: pre-install-rb install-rb-default
117
+ install-rb-default: pre-install-rb-default
118
+ pre-install-rb: Makefile
119
+ pre-install-rb-default: Makefile
120
+ $(RUBYARCHDIR):
121
+ $(MAKEDIRS) $@
122
+
123
+ site-install: site-install-so site-install-rb
124
+ site-install-so: install-so
125
+ site-install-rb: install-rb
126
+
127
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
128
+
129
+ .cc.o:
130
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
131
+
132
+ .cxx.o:
133
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
134
+
135
+ .cpp.o:
136
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
137
+
138
+ .C.o:
139
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
140
+
141
+ .c.o:
142
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
143
+
144
+ $(DLLIB): $(OBJS)
145
+ @-$(RM) $@
146
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
147
+
148
+
149
+
150
+ $(OBJS): ruby.h defines.h
data/ext/bbcode.cpp ADDED
@@ -0,0 +1,37 @@
1
+ // Include the Ruby headers and goodies
2
+ #include "ruby.h"
3
+ #include <iostream>
4
+ #include <fstream>
5
+ #include <string>
6
+ #include <sstream>
7
+ #include <stdexcept>
8
+ #include "bbcode_parser.h"
9
+
10
+ typedef VALUE (ruby_method)(...);
11
+ using namespace std;
12
+ using namespace bbcode;
13
+
14
+ // Prototype for the initialization method - Ruby calls this, not you
15
+ extern "C" void Init_bbcode();
16
+
17
+ // Prototype for our method 'parse_string' - methods are prefixed by 'method_' here
18
+ VALUE method_parse_string(VALUE self, VALUE arg);
19
+
20
+
21
+ // The initialization method for this module
22
+ extern "C" void Init_bbcode() {
23
+ VALUE BBCode = rb_define_module("BBCode");
24
+ rb_define_singleton_method(BBCode, "parse_string", (ruby_method*)method_parse_string, 1);
25
+ }
26
+
27
+ // Our 'parse_string' method.. it simply returns a value of '10' for now.
28
+ VALUE method_parse_string(VALUE self, VALUE arg) {
29
+ string s = RSTRING(arg)->ptr;
30
+ parser bbparser;
31
+ stringstream str(s);
32
+ bbparser.source_stream(str);
33
+ bbparser.parse();
34
+ const char* result = bbparser.content().c_str();
35
+ return rb_str_new2(result);
36
+ }
37
+
@@ -0,0 +1,179 @@
1
+ /*!
2
+
3
+ Abstract:
4
+ this file is a part of bbcode library
5
+
6
+ Author:
7
+ Igor Franchuk (sprog@online.ru)
8
+
9
+ Last Update:
10
+ $Id: bbcode_config.h,v 1.1 2007/12/19 19:13:30 lanthruster Exp $
11
+ Version: 0.01
12
+ */
13
+
14
+ #ifndef BBCODE_CONFIG_H
15
+ #define BBCODE_CONFIG_H
16
+ #pragma once
17
+
18
+ #include <string>
19
+ #include <istream>
20
+ #include <iostream>
21
+
22
+ namespace{
23
+ using std::string;
24
+ using std::istream;
25
+ using std::cin;
26
+ }
27
+
28
+ namespace bbcode{
29
+
30
+ /* lexems */
31
+ enum lexeme{SPACE, WORD, OFFTOPIC, UNDERLINE, DELIMITER, TERM,
32
+ ITALIC, BOLD, HEADER, SMALL, HR, IMG, RED, SUB, SUP, URL, PRE, QQUOTE, CODE, FACE, LIST, SIZE,
33
+ COLOR, ORANGE, YELLOW, GREEN, BLUE, WHITE, PURPLE, BLACK, EMAIL, OLIST,
34
+ EQUALITY='=', COLON = ':', SEMICOLON = ';', QUOTE = '"',
35
+ ENTER = '\r', SPACEBAR = ' ', CR_RETURN = '\n', LEFT_SQUARE_BRACKET = '[', RIGHT_SQUARE_BRACKET = ']',
36
+ SLASH = '/', MULT = '*'};
37
+
38
+
39
+ const string _THIS_MODULE_STR_IDENT = "bbcode library";
40
+ const string _RND_GENERATOR_DICTIONARY = "abcdefghijklmnopqrstuvwxyz0123456789";
41
+ const size_t _DEFAULT_BUFFER_SIZE = 8192; /* we're using default buffer size of 8192 bytes */
42
+
43
+ const string _HTML_LT = "<";
44
+ const string _HTML_GT = ">";
45
+ const string _HTML_BSLASH = "/";
46
+
47
+ const string _BOLD = "B";
48
+ const string _ITALIC = "I";
49
+ const string _UNDERLINE = "U";
50
+ const string _HEADER = "H";
51
+ const string _SMALL = "S";
52
+ const string _OFFTOPIC = "O";
53
+ const string _Q = "Q";
54
+ const string _MULT = "*";
55
+ const string _QUOTE = "QUOTE";
56
+ const string _AQUOTE = "AQUOTE";
57
+ const string _HR = "HR";
58
+ const string _IMG = "IMG";
59
+ const string _RED = "RED";
60
+ const string _SUB = "SUB";
61
+ const string _SUP = "SUP";
62
+ const string _URL = "URL";
63
+ const string _PRE = "PRE";
64
+ const string _CODE = "CODE";
65
+ const string _FACE = "FACE";
66
+ const string _LIST = "LIST";
67
+ const string _OLIST = "OLIST";
68
+ const string _SIZE = "SIZE";
69
+ const string _COLOR = "COLOR";
70
+ const string _ORANGE = "ORANGE";
71
+ const string _YELLOW = "YELLOW";
72
+ const string _GREEN = "GREEN";
73
+ const string _BLUE = "BLUE";
74
+ const string _PURPLE = "PURPLE";
75
+ const string _WHITE = "WHITE";
76
+ const string _BLACK = "BLACK";
77
+ const string _EMAIL = "EMAIL";
78
+
79
+ const string _TITLE = "TITLE";
80
+
81
+
82
+ const size_t DEBUG_MODE_ON = 1;
83
+ const size_t DUBUG_MODE_OFF = 2396744;
84
+
85
+
86
+ const string _SUPPORTED_BBTAGS =
87
+ "B ! <b>|\
88
+ /B ! </b>|\
89
+ I ! <i>|\
90
+ /I ! </i>|\
91
+ U ! <u>|\
92
+ /U ! </u>|\
93
+ H ! <h>|\
94
+ /H ! </h>|\
95
+ S ! <small>|\
96
+ /S ! </small>|\
97
+ SUB ! <sub>|\
98
+ /SUB ! </sub>|\
99
+ SUP ! <sup>|\
100
+ /SUP ! </sup>|\
101
+ O ! <font face=\"Verdana, Arial\" color=\"gray\" size=\"2\">|\
102
+ /O ! </font>|\
103
+ COLOR ! <font face=\"Verdana, Arial\" color=\"$COLOR\" size=\"2\">|\
104
+ /COLOR ! </font>|\
105
+ RED ! <font face=\"Verdana, Arial\" color=\"red\" size=\"2\">|\
106
+ /RED ! </font>|\
107
+ ORANGE ! <font face=\"Verdana, Arial\" color=\"orange\" size=\"2\">|\
108
+ /ORANGE ! </font>|\
109
+ YELLOW ! <font face=\"Verdana, Arial\" color=\"yellow\" size=\"2\">|\
110
+ /YELLOW ! </font>|\
111
+ GREEN ! <font face=\"Verdana, Arial\" color=\"green\" size=\"2\">|\
112
+ /GREEN ! </font>|\
113
+ BLUE ! <font face=\"Verdana, Arial\" color=\"blue\" size=\"2\">|\
114
+ /BLUE ! </font>|\
115
+ PURPLE ! <font face=\"Verdana, Arial\" color=\"purple\" size=\"2\">|\
116
+ /PURPLE ! </font>|\
117
+ WHITE ! <font face=\"Verdana, Arial\" color=\"white\" size=\"2\">|\
118
+ /WHITE ! </font>|\
119
+ BLACK ! <font face=\"Verdana, Arial\" color=\"black\" size=\"2\">|\
120
+ /BLACK ! </font>|\
121
+ SIZE ! <font face=\"Verdana, Arial\" color=\"#cc0000\" size=\"$SIZE\">|\
122
+ /SIZE ! </font>|\
123
+ FACE ! <font face=\"$FACE\">|\
124
+ /FACE ! </font>|\
125
+ URL ! <a href=\"$URL\">|\
126
+ /URL ! </a>|\
127
+ PRE ! <pre>|\
128
+ /PRE ! </pre>|\
129
+ CODE ! <code>|\
130
+ /CODE ! </code>|\
131
+ IMG ! <a href=\"$IMG\" target=\"_blank\" title=\"$TITLE\">|\
132
+ /IMG ! </a>|\
133
+ LIST ! <ul>|\
134
+ /LIST ! </ul>|\
135
+ OLIST ! <ol>|\
136
+ /OLIST ! </ol>|\
137
+ * ! <li>|\
138
+ /* ! </li>|\
139
+ EMAIL ! <a href=\"mailto:$EMAIL\" target=\"_blank\">|\
140
+ /EMAIL ! </a>|\
141
+ HR ! <hr>|\
142
+ QUOTE ! <div style=\"margin:20px; margin-top:5px;\"><div style=\"margin-bottom:2px\">Quote:</div><table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td style=\"border:1px inset\"><div>Originally Posted by <strong>$QUOTE</strong></div><div style=\"font-style:italic\">|\
143
+ /QUOTE ! </div></td></tr></table></div>|";
144
+ const string _SHEMA_DELIMITER = "|";
145
+ const string _SHEMA_TAG_DELIMITER = "!";
146
+ const string _COLON = ":";
147
+
148
+ const string _BBTAG_IS_UNAVAILABLE_RET = "";
149
+ const string _SCHEMA_MACRO_PREFIX = "$";
150
+
151
+ const size_t _MAXIMUM_PROTO_LENGTH = 6;
152
+
153
+
154
+ /* we store user setup in this structure */
155
+
156
+ struct parser_config{
157
+
158
+ enum flag{store_data_in_memory=0, store_data_in_file=1};
159
+
160
+ size_t _config; //we keep our configuratin here
161
+ istream* _source_stream; //source, from where we're going to read our files
162
+ size_t _read_buffer_size; // buffer we read data into
163
+
164
+ parser_config(istream& source_stream, size_t read_buffer_size) :
165
+ _source_stream(&source_stream),
166
+ _config(0),
167
+ _read_buffer_size(read_buffer_size){}
168
+
169
+
170
+ parser_config(void) :
171
+ _source_stream(&cin),
172
+ _config(0),
173
+ _read_buffer_size(_DEFAULT_BUFFER_SIZE){}
174
+
175
+ };
176
+
177
+ }
178
+
179
+ #endif