unichars 0.2 → 0.3

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.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'mkmf'
2
4
 
3
5
  unless pkg_config('glib-2.0')
@@ -1,6 +1,14 @@
1
1
  #include <ruby.h>
2
2
  #include <glib.h>
3
3
 
4
+ /*
5
+ * call-seq:
6
+ * utf8_size(string)
7
+ *
8
+ * Returns the length of the string expressed in codepoints.
9
+ *
10
+ * Glib.utf8_size('A ehm…, word.') #=> 13
11
+ */
4
12
  static VALUE utf8_size(VALUE self, VALUE string)
5
13
  {
6
14
  VALUE result;
@@ -11,6 +19,14 @@ static VALUE utf8_size(VALUE self, VALUE string)
11
19
  return result;
12
20
  }
13
21
 
22
+ /*
23
+ * call-seq:
24
+ * utf8_upcase(string)
25
+ *
26
+ * Returns the string in capitals if they are are available for the supplied characters.
27
+ *
28
+ * Glib.utf8_upcase('Sluß') #=> SLUSS
29
+ */
14
30
  static VALUE utf8_upcase(VALUE self, VALUE string)
15
31
  {
16
32
  VALUE result;
@@ -23,6 +39,14 @@ static VALUE utf8_upcase(VALUE self, VALUE string)
23
39
  return result;
24
40
  }
25
41
 
42
+ /*
43
+ * call-seq:
44
+ * utf8_downcase(string)
45
+ *
46
+ * Returns the string in lowercase characters if they are are available for the supplied characters.
47
+ *
48
+ * Glib.utf8_downcase('ORGANISÉE') #=> organisée
49
+ */
26
50
  static VALUE utf8_downcase(VALUE self, VALUE string)
27
51
  {
28
52
  VALUE result;
@@ -35,6 +59,14 @@ static VALUE utf8_downcase(VALUE self, VALUE string)
35
59
  return result;
36
60
  }
37
61
 
62
+ /*
63
+ * call-seq:
64
+ * utf8_reverse(string)
65
+ *
66
+ * Returns a string with the characters in reverse order.
67
+ *
68
+ * Glib.utf8_reverse('Comment ça va?') #=> av aç tnemmoC
69
+ */
38
70
  static VALUE utf8_reverse(VALUE self, VALUE string)
39
71
  {
40
72
  VALUE result;
@@ -47,6 +79,50 @@ static VALUE utf8_reverse(VALUE self, VALUE string)
47
79
  return result;
48
80
  }
49
81
 
82
+
83
+ /*
84
+ * call-seq:
85
+ * utf_normalize(string, form)
86
+ *
87
+ * Returns the normalized form of the string. See http://www.unicode.org/reports/tr15/tr15-29.html for more
88
+ * information about normalization.
89
+ *
90
+ * <i>form</i> can be one of the following: <tt>:c</tt>, <tt>:kc</tt>, <tt>:d</tt>, or <tt>:kd</tt>.
91
+ *
92
+ * decomposed = [101, 769].pack('U*')
93
+ * composed = Glib.utf8_normalize(decomposed, :kc)
94
+ * composed.unpack('U*') #=> [233]
95
+ */
96
+ static VALUE utf8_normalize(VALUE self, VALUE string, VALUE form)
97
+ {
98
+ VALUE result;
99
+ gchar *temp;
100
+ GNormalizeMode mode;
101
+
102
+ Check_Type(string, T_STRING);
103
+ Check_Type(form, T_SYMBOL);
104
+
105
+ if (ID2SYM(rb_intern("d")) == form) {
106
+ mode = G_NORMALIZE_NFD;
107
+ } else if (ID2SYM(rb_intern("c")) == form) {
108
+ mode = G_NORMALIZE_NFC;
109
+ } else if (ID2SYM(rb_intern("kd")) == form) {
110
+ mode = G_NORMALIZE_NFKD;
111
+ } else if (ID2SYM(rb_intern("kc")) == form) {
112
+ mode = G_NORMALIZE_NFKC;
113
+ } else {
114
+ rb_raise(rb_eArgError, "%s is not a valid normalization form, options are: :d, :kd, :c, or :kc", RSTRING(rb_inspect(form))->ptr);
115
+ }
116
+
117
+ temp = g_utf8_normalize(StringValuePtr(string), RSTRING(string)->len, mode);
118
+ result = rb_str_new2(temp);
119
+
120
+ return result;
121
+ }
122
+
123
+
124
+ /* The Glib module holds methods which wrap Glib2 functions.
125
+ */
50
126
  void
51
127
  Init_glib()
52
128
  {
@@ -57,4 +133,5 @@ Init_glib()
57
133
  rb_define_module_function(mGlib, "utf8_upcase", utf8_upcase, 1);
58
134
  rb_define_module_function(mGlib, "utf8_downcase", utf8_downcase, 1);
59
135
  rb_define_module_function(mGlib, "utf8_reverse", utf8_reverse, 1);
136
+ rb_define_module_function(mGlib, "utf8_normalize", utf8_normalize, 2);
60
137
  }
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  class Chars
2
4
  attr_reader :wrapped_string
3
5
  alias to_s wrapped_string
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'glib'
2
4
 
3
5
  begin
@@ -8,6 +10,12 @@ rescue NameError
8
10
  end
9
11
 
10
12
  class Unichars
13
+ NORMALIZATION_FORMS = [:c, :kc, :d, :kd]
14
+
15
+ class << self
16
+ attr_accessor :default_normalization_form
17
+ end
18
+
11
19
  def size
12
20
  Glib.utf8_size(@wrapped_string)
13
21
  end
@@ -23,4 +31,10 @@ class Unichars
23
31
  def reverse
24
32
  self.class.new(Glib.utf8_reverse(@wrapped_string))
25
33
  end
26
- end
34
+
35
+ def normalize(form=Unichars.default_normalization_form)
36
+ self.class.new(Glib.utf8_normalize(@wrapped_string, form))
37
+ end
38
+ end
39
+
40
+ Unichars.default_normalization_form = :kc
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unichars
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-24 00:00:00 +01:00
12
+ date: 2008-12-22 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,16 +22,13 @@ extensions:
22
22
  extra_rdoc_files:
23
23
  - README
24
24
  - LICENSE
25
+ - ext/glib/glib.c
25
26
  files:
26
27
  - lib/chars.rb
27
28
  - lib/unichars.rb
28
29
  - ext/glib
29
30
  - ext/glib/extconf.rb
30
- - ext/glib/glib.bundle
31
31
  - ext/glib/glib.c
32
- - ext/glib/glib.o
33
- - ext/glib/Makefile
34
- - ext/glib/mkmf.log
35
32
  - README
36
33
  - LICENSE
37
34
  has_rdoc: true
@@ -1,149 +0,0 @@
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
Binary file
Binary file
@@ -1,5 +0,0 @@
1
- package configuration for glib-2.0
2
- cflags: -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include
3
- ldflags: -L/opt/local/lib
4
- libs: -lglib-2.0 -lintl -liconv
5
-