rev |
line source |
jbe@0
|
1 ##
|
jbe@0
|
2 # Copyright (c) 2006, FlexiGuided GmbH, Berlin, Germany
|
jbe@0
|
3 # Author: Jan Behrens <jan.behrens@flexiguided.de>
|
jbe@0
|
4 # All rights reserved.
|
jbe@0
|
5 #
|
jbe@0
|
6 # Redistribution and use in source and binary forms, with or without
|
jbe@0
|
7 # modification, are permitted provided that the following conditions are
|
jbe@0
|
8 # met:
|
jbe@0
|
9 #
|
jbe@0
|
10 # 1. Redistributions of source code must retain the above copyright
|
jbe@0
|
11 # notice, this list of conditions and the following disclaimer.
|
jbe@0
|
12 # 2. Redistributions in binary form must reproduce the above copyright
|
jbe@0
|
13 # notice, this list of conditions and the following disclaimer in the
|
jbe@0
|
14 # documentation and/or other materials provided with the distribution.
|
jbe@0
|
15 # 3. Neither the name of the FlexiGuided GmbH nor the names of its
|
jbe@0
|
16 # contributors may be used to endorse or promote products derived from
|
jbe@0
|
17 # this software without specific prior written permission.
|
jbe@0
|
18 #
|
jbe@0
|
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
jbe@0
|
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
jbe@0
|
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
jbe@0
|
22 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
jbe@0
|
23 # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
jbe@0
|
24 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
jbe@0
|
25 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
jbe@0
|
26 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
jbe@0
|
27 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
jbe@0
|
28 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
jbe@0
|
29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
jbe@0
|
30 #
|
jbe@0
|
31 ##
|
jbe@0
|
32
|
jbe@0
|
33
|
jbe@0
|
34 ##
|
jbe@0
|
35 # File name: ruby/utf8proc.rb
|
jbe@0
|
36 # Version: 0.1
|
jbe@0
|
37 # Last changed: 2006-05-31
|
jbe@0
|
38 #
|
jbe@0
|
39 # Description:
|
jbe@0
|
40 # Part of the ruby wrapper for libutf8proc, which is written in ruby.
|
jbe@0
|
41 ##
|
jbe@0
|
42
|
jbe@0
|
43
|
jbe@0
|
44 require 'utf8proc_native'
|
jbe@0
|
45
|
jbe@0
|
46 module Utf8Proc
|
jbe@0
|
47 SpecialChars = {
|
jbe@0
|
48 :HT => "\x09",
|
jbe@0
|
49 :LF => "\x0A",
|
jbe@0
|
50 :VT => "\x0B",
|
jbe@0
|
51 :FF => "\x0C",
|
jbe@0
|
52 :CR => "\x0D",
|
jbe@0
|
53 :FS => "\x1C",
|
jbe@0
|
54 :GS => "\x1D",
|
jbe@0
|
55 :RS => "\x1E",
|
jbe@0
|
56 :US => "\x1F",
|
jbe@0
|
57 :LS => "\xE2\x80\xA8",
|
jbe@0
|
58 :PS => "\xE2\x80\xA9",
|
jbe@0
|
59 }
|
jbe@0
|
60 end
|
jbe@0
|
61
|
jbe@0
|
62 class String
|
jbe@0
|
63 def utf8map(*option_array)
|
jbe@0
|
64 options = 0
|
jbe@0
|
65 option_array.each do |option|
|
jbe@0
|
66 flag = Utf8Proc::Options[option]
|
jbe@0
|
67 raise ArgumentError, "Unknown argument given to String#utf8map." unless
|
jbe@0
|
68 flag
|
jbe@0
|
69 options |= flag
|
jbe@0
|
70 end
|
jbe@0
|
71 return Utf8Proc::utf8map(self, options)
|
jbe@0
|
72 end
|
jbe@0
|
73 def utf8map!(*option_array)
|
jbe@0
|
74 self.replace(self.utf8map(*option_array))
|
jbe@0
|
75 end
|
jbe@0
|
76 def utf8nfd; utf8map( :stable); end
|
jbe@0
|
77 def utf8nfd!; utf8map!(:stable); end
|
jbe@0
|
78 def utf8nfc; utf8map( :stable, :compose); end
|
jbe@0
|
79 def utf8nfc!; utf8map!(:stable, :compose); end
|
jbe@0
|
80 def utf8nfkd; utf8map( :stable, :compat); end
|
jbe@0
|
81 def utf8nfkd!; utf8map!(:stable, :compat); end
|
jbe@0
|
82 def utf8nfkc; utf8map( :stable, :compose, :compat); end
|
jbe@0
|
83 def utf8nfkc!; utf8map!(:stable, :compose, :compat); end
|
jbe@0
|
84 end
|
jbe@0
|
85
|
jbe@0
|
86 class Integer
|
jbe@0
|
87 def utf8
|
jbe@0
|
88 return Utf8Proc::utf8char(self)
|
jbe@0
|
89 end
|
jbe@0
|
90 end
|
jbe@0
|
91
|
jbe@0
|
92
|