unichars 0.2
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/LICENSE +18 -0
- data/README +65 -0
- data/ext/glib/Makefile +149 -0
- data/ext/glib/extconf.rb +9 -0
- data/ext/glib/glib.bundle +0 -0
- data/ext/glib/glib.c +60 -0
- data/ext/glib/glib.o +0 -0
- data/ext/glib/mkmf.log +5 -0
- data/lib/chars.rb +47 -0
- data/lib/unichars.rb +26 -0
- metadata +64 -0
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2008 Manfred Stienstra, Fingertips <manfred@fngtps.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
-%{ Unichars }%-
|
2
|
+
|
3
|
+
Unichars is a simple wrapper around Glib2. It was originally written to speed up ActiveSupport::Multibyte on Ruby 1.8 but it can probably used for other things as well.
|
4
|
+
|
5
|
+
|
6
|
+
--^^--^^- INSTALLING -^^--^^--
|
7
|
+
|
8
|
+
INSTALLING ON MAC OS X
|
9
|
+
|
10
|
+
$ port install glib2
|
11
|
+
$ gem install unichars
|
12
|
+
|
13
|
+
INSTALLING ON DEBIAN
|
14
|
+
|
15
|
+
$ apt-get install libglib2.0-dev
|
16
|
+
$ gem install unichars
|
17
|
+
|
18
|
+
|
19
|
+
--^^--^^- EXAMPLES -^^--^^--
|
20
|
+
|
21
|
+
FOR USE WITH RAILS
|
22
|
+
|
23
|
+
In config/environment.rb add:
|
24
|
+
|
25
|
+
config.gem 'unichars'
|
26
|
+
|
27
|
+
Add config/initializers/unichars.rb:
|
28
|
+
|
29
|
+
ActiveSupport::Multibyte.proxy_class = Unichars
|
30
|
+
|
31
|
+
After that you can just use Unichars through the character proxy on String:
|
32
|
+
|
33
|
+
'¡Ay Dios mío!'.chars.reverse
|
34
|
+
|
35
|
+
FOR USE WITH ACTIVESUPPORT WITHOUT RAILS
|
36
|
+
|
37
|
+
Note that you probably want to load ActiveSupport before loading Unichars because Unichars subclasses itself from ActiveSupport::Multibyte::Chars when you do so.
|
38
|
+
|
39
|
+
require 'rubygems' rescue LoadError
|
40
|
+
require 'activesupport'
|
41
|
+
require 'unichars'
|
42
|
+
ActiveSupport::Multibyte.proxy_class = Unichars
|
43
|
+
|
44
|
+
After that you can just use Unichars through the character proxy on String:
|
45
|
+
|
46
|
+
'¡Ay Dios mío!'.chars.reverse
|
47
|
+
|
48
|
+
FOR USE WITHOUT ACTIVESUPPORT
|
49
|
+
|
50
|
+
Yeah, so, ehm. Yeah.
|
51
|
+
|
52
|
+
require 'rubygems' rescue LoadError
|
53
|
+
require 'unichars'
|
54
|
+
|
55
|
+
After that you can do:
|
56
|
+
|
57
|
+
Unichars.new('¡Ay Dios mío!').reverse
|
58
|
+
|
59
|
+
Or maybe:
|
60
|
+
|
61
|
+
class String
|
62
|
+
def chars
|
63
|
+
Unichars.new(self)
|
64
|
+
end
|
65
|
+
end
|
data/ext/glib/Makefile
ADDED
@@ -0,0 +1,149 @@
|
|
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 -arch i386 -Os -pipe -fno-common -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include
|
45
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
46
|
+
CPPFLAGS =
|
47
|
+
CXXFLAGS = $(CFLAGS)
|
48
|
+
DLDFLAGS = -L. -arch ppc -arch i386 -L/opt/local/lib
|
49
|
+
LDSHARED = cc -arch ppc -arch i386 -pipe -bundle -undefined dynamic_lookup
|
50
|
+
AR = ar
|
51
|
+
EXEEXT =
|
52
|
+
|
53
|
+
RUBY_INSTALL_NAME = ruby
|
54
|
+
RUBY_SO_NAME = ruby
|
55
|
+
arch = universal-darwin9.0
|
56
|
+
sitearch = universal-darwin9.0
|
57
|
+
ruby_version = 1.8
|
58
|
+
ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
|
59
|
+
RUBY = $(ruby)
|
60
|
+
RM = rm -f
|
61
|
+
MAKEDIRS = mkdir -p
|
62
|
+
INSTALL = /usr/bin/install -c
|
63
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
64
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
65
|
+
COPY = cp
|
66
|
+
|
67
|
+
#### End of system configuration section. ####
|
68
|
+
|
69
|
+
preload =
|
70
|
+
|
71
|
+
libpath = . $(libdir)
|
72
|
+
LIBPATH = -L"." -L"$(libdir)"
|
73
|
+
DEFFILE =
|
74
|
+
|
75
|
+
CLEANFILES = mkmf.log
|
76
|
+
DISTCLEANFILES =
|
77
|
+
|
78
|
+
extout =
|
79
|
+
extout_prefix =
|
80
|
+
target_prefix =
|
81
|
+
LOCAL_LIBS =
|
82
|
+
LIBS = $(LIBRUBYARG_SHARED) -lglib-2.0 -lintl -liconv -lpthread -ldl -lm
|
83
|
+
SRCS = glib.c
|
84
|
+
OBJS = glib.o
|
85
|
+
TARGET = glib
|
86
|
+
DLLIB = $(TARGET).bundle
|
87
|
+
EXTSTATIC =
|
88
|
+
STATIC_LIB =
|
89
|
+
|
90
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
91
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
92
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
93
|
+
|
94
|
+
TARGET_SO = $(DLLIB)
|
95
|
+
CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
|
96
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
97
|
+
|
98
|
+
all: $(DLLIB)
|
99
|
+
static: $(STATIC_LIB)
|
100
|
+
|
101
|
+
clean:
|
102
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
103
|
+
|
104
|
+
distclean: clean
|
105
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
106
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
107
|
+
|
108
|
+
realclean: distclean
|
109
|
+
install: install-so install-rb
|
110
|
+
|
111
|
+
install-so: $(RUBYARCHDIR)
|
112
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
113
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
114
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
115
|
+
install-rb: pre-install-rb install-rb-default
|
116
|
+
install-rb-default: pre-install-rb-default
|
117
|
+
pre-install-rb: Makefile
|
118
|
+
pre-install-rb-default: Makefile
|
119
|
+
$(RUBYARCHDIR):
|
120
|
+
$(MAKEDIRS) $@
|
121
|
+
|
122
|
+
site-install: site-install-so site-install-rb
|
123
|
+
site-install-so: install-so
|
124
|
+
site-install-rb: install-rb
|
125
|
+
|
126
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
127
|
+
|
128
|
+
.cc.o:
|
129
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
130
|
+
|
131
|
+
.cxx.o:
|
132
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
133
|
+
|
134
|
+
.cpp.o:
|
135
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
136
|
+
|
137
|
+
.C.o:
|
138
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
139
|
+
|
140
|
+
.c.o:
|
141
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
142
|
+
|
143
|
+
$(DLLIB): $(OBJS)
|
144
|
+
@-$(RM) $@
|
145
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
$(OBJS): ruby.h defines.h
|
data/ext/glib/extconf.rb
ADDED
Binary file
|
data/ext/glib/glib.c
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <glib.h>
|
3
|
+
|
4
|
+
static VALUE utf8_size(VALUE self, VALUE string)
|
5
|
+
{
|
6
|
+
VALUE result;
|
7
|
+
|
8
|
+
Check_Type(string, T_STRING);
|
9
|
+
result = ULONG2NUM(g_utf8_strlen(StringValuePtr(string), RSTRING(string)->len));
|
10
|
+
|
11
|
+
return result;
|
12
|
+
}
|
13
|
+
|
14
|
+
static VALUE utf8_upcase(VALUE self, VALUE string)
|
15
|
+
{
|
16
|
+
VALUE result;
|
17
|
+
gchar *temp;
|
18
|
+
|
19
|
+
Check_Type(string, T_STRING);
|
20
|
+
temp = g_utf8_strup(StringValuePtr(string), RSTRING(string)->len);
|
21
|
+
result = rb_str_new2(temp);
|
22
|
+
|
23
|
+
return result;
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE utf8_downcase(VALUE self, VALUE string)
|
27
|
+
{
|
28
|
+
VALUE result;
|
29
|
+
gchar *temp;
|
30
|
+
|
31
|
+
Check_Type(string, T_STRING);
|
32
|
+
temp = g_utf8_strdown(StringValuePtr(string), RSTRING(string)->len);
|
33
|
+
result = rb_str_new2(temp);
|
34
|
+
|
35
|
+
return result;
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE utf8_reverse(VALUE self, VALUE string)
|
39
|
+
{
|
40
|
+
VALUE result;
|
41
|
+
gchar *temp;
|
42
|
+
|
43
|
+
Check_Type(string, T_STRING);
|
44
|
+
temp = g_utf8_strreverse(StringValuePtr(string), RSTRING(string)->len);
|
45
|
+
result = rb_str_new2(temp);
|
46
|
+
|
47
|
+
return result;
|
48
|
+
}
|
49
|
+
|
50
|
+
void
|
51
|
+
Init_glib()
|
52
|
+
{
|
53
|
+
VALUE mGlib;
|
54
|
+
|
55
|
+
mGlib = rb_define_module("Glib");
|
56
|
+
rb_define_module_function(mGlib, "utf8_size", utf8_size, 1);
|
57
|
+
rb_define_module_function(mGlib, "utf8_upcase", utf8_upcase, 1);
|
58
|
+
rb_define_module_function(mGlib, "utf8_downcase", utf8_downcase, 1);
|
59
|
+
rb_define_module_function(mGlib, "utf8_reverse", utf8_reverse, 1);
|
60
|
+
}
|
data/ext/glib/glib.o
ADDED
Binary file
|
data/ext/glib/mkmf.log
ADDED
data/lib/chars.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Chars
|
2
|
+
attr_reader :wrapped_string
|
3
|
+
alias to_s wrapped_string
|
4
|
+
alias to_str wrapped_string
|
5
|
+
|
6
|
+
# Creates a new Chars instance by wrapping _string_.
|
7
|
+
def initialize(string)
|
8
|
+
@wrapped_string = string
|
9
|
+
end
|
10
|
+
|
11
|
+
# Forward all undefined methods to the wrapped string.
|
12
|
+
def method_missing(method, *args, &block)
|
13
|
+
if method.to_s =~ /!$/
|
14
|
+
@wrapped_string.send(method, *args, &block)
|
15
|
+
self
|
16
|
+
else
|
17
|
+
result = @wrapped_string.send(method, *args, &block)
|
18
|
+
result.kind_of?(String) ? self.class.new(result) : result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns +true+ if _obj_ responds to the given method. Private methods are included in the search
|
23
|
+
# only if the optional second parameter evaluates to +true+.
|
24
|
+
def respond_to?(method, include_private=false)
|
25
|
+
super || @wrapped_string.respond_to?(method, include_private) || false
|
26
|
+
end
|
27
|
+
|
28
|
+
include Comparable
|
29
|
+
|
30
|
+
# Returns <tt>-1</tt>, <tt>0</tt> or <tt>+1</tt> depending on whether the Chars object is to be sorted before,
|
31
|
+
# equal or after the object on the right side of the operation. It accepts any object that implements +to_s+.
|
32
|
+
# See <tt>String#<=></tt> for more details.
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
# 'é'.mb_chars <=> 'ü'.mb_chars #=> -1
|
36
|
+
def <=>(other)
|
37
|
+
@wrapped_string <=> other.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a new Chars object containing the _other_ object concatenated to the string.
|
41
|
+
#
|
42
|
+
# Example:
|
43
|
+
# ('Café'.mb_chars + ' périferôl').to_s #=> "Café périferôl"
|
44
|
+
def +(other)
|
45
|
+
self << other
|
46
|
+
end
|
47
|
+
end
|
data/lib/unichars.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'glib'
|
2
|
+
|
3
|
+
begin
|
4
|
+
class Unichars < ActiveSupport::Multibyte::Chars; end
|
5
|
+
rescue NameError
|
6
|
+
require 'chars'
|
7
|
+
class Unichars < Chars; end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Unichars
|
11
|
+
def size
|
12
|
+
Glib.utf8_size(@wrapped_string)
|
13
|
+
end
|
14
|
+
|
15
|
+
def upcase
|
16
|
+
self.class.new(Glib.utf8_upcase(@wrapped_string))
|
17
|
+
end
|
18
|
+
|
19
|
+
def downcase
|
20
|
+
self.class.new(Glib.utf8_downcase(@wrapped_string))
|
21
|
+
end
|
22
|
+
|
23
|
+
def reverse
|
24
|
+
self.class.new(Glib.utf8_reverse(@wrapped_string))
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unichars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manfred Stienstra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-24 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Unichars is a wrapper around Glib2 UTF8 functions.
|
17
|
+
email: manfred@fngtps.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/glib/extconf.rb
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- lib/chars.rb
|
27
|
+
- lib/unichars.rb
|
28
|
+
- ext/glib
|
29
|
+
- ext/glib/extconf.rb
|
30
|
+
- ext/glib/glib.bundle
|
31
|
+
- ext/glib/glib.c
|
32
|
+
- ext/glib/glib.o
|
33
|
+
- ext/glib/Makefile
|
34
|
+
- ext/glib/mkmf.log
|
35
|
+
- README
|
36
|
+
- LICENSE
|
37
|
+
has_rdoc: true
|
38
|
+
homepage:
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --charset=utf-8
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Unichars is a wrapper around Glib2 UTF8 functions. It was written to speed up ActiveSupport::Multibyte, but I'm sure people can find other uses for it.
|
63
|
+
test_files: []
|
64
|
+
|