utf8proc
annotate ruby/utf8proc.rb @ 9:951e73a98021
Version 1.1.3
- Added a function utf8proc_version returning a string containing the version number of the library.
- Included a target libutf8proc.dylib for MacOSX.
- PostgreSQL 8.3 compatibility (use of SET_VARSIZE macro)
- Added a function utf8proc_version returning a string containing the version number of the library.
- Included a target libutf8proc.dylib for MacOSX.
- PostgreSQL 8.3 compatibility (use of SET_VARSIZE macro)
author | jbe |
---|---|
date | Fri May 01 12:00:00 2009 +0200 (2009-05-01) |
parents | fcfd8c836c64 |
children | 00d2bcbdc945 |
rev | line source |
---|---|
jbe@7 | 1 # Copyright (c) 2006-2007 Jan Behrens, FlexiGuided GmbH, Berlin |
jbe@7 | 2 # |
jbe@7 | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
jbe@7 | 4 # copy of this software and associated documentation files (the "Software"), |
jbe@7 | 5 # to deal in the Software without restriction, including without limitation |
jbe@7 | 6 # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
jbe@7 | 7 # and/or sell copies of the Software, and to permit persons to whom the |
jbe@7 | 8 # Software is furnished to do so, subject to the following conditions: |
jbe@7 | 9 # |
jbe@7 | 10 # The above copyright notice and this permission notice shall be included in |
jbe@7 | 11 # all copies or substantial portions of the Software. |
jbe@7 | 12 # |
jbe@7 | 13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
jbe@7 | 14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
jbe@7 | 15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
jbe@7 | 16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
jbe@7 | 17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
jbe@7 | 18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
jbe@7 | 19 # DEALINGS IN THE SOFTWARE. |
jbe@0 | 20 |
jbe@7 | 21 |
jbe@7 | 22 # |
jbe@7 | 23 # File name: ruby/utf8proc.rb |
jbe@7 | 24 # Version: 1.1.1 |
jbe@7 | 25 # Last changed: 2006-09-17 |
jbe@7 | 26 # |
jbe@7 | 27 # Description: |
jbe@7 | 28 # Part of the ruby wrapper for libutf8proc, which is written in ruby. |
jbe@7 | 29 # |
jbe@0 | 30 |
jbe@0 | 31 |
jbe@0 | 32 require 'utf8proc_native' |
jbe@0 | 33 |
jbe@2 | 34 |
jbe@0 | 35 module Utf8Proc |
jbe@2 | 36 |
jbe@0 | 37 SpecialChars = { |
jbe@0 | 38 :HT => "\x09", |
jbe@0 | 39 :LF => "\x0A", |
jbe@0 | 40 :VT => "\x0B", |
jbe@0 | 41 :FF => "\x0C", |
jbe@0 | 42 :CR => "\x0D", |
jbe@0 | 43 :FS => "\x1C", |
jbe@0 | 44 :GS => "\x1D", |
jbe@0 | 45 :RS => "\x1E", |
jbe@0 | 46 :US => "\x1F", |
jbe@0 | 47 :LS => "\xE2\x80\xA8", |
jbe@0 | 48 :PS => "\xE2\x80\xA9", |
jbe@0 | 49 } |
jbe@2 | 50 |
jbe@2 | 51 module StringExtensions |
jbe@2 | 52 def utf8map(*option_array) |
jbe@2 | 53 options = 0 |
jbe@2 | 54 option_array.each do |option| |
jbe@2 | 55 flag = Utf8Proc::Options[option] |
jbe@2 | 56 raise ArgumentError, "Unknown argument given to String#utf8map." unless |
jbe@2 | 57 flag |
jbe@2 | 58 options |= flag |
jbe@2 | 59 end |
jbe@2 | 60 return Utf8Proc::utf8map(self, options) |
jbe@2 | 61 end |
jbe@2 | 62 def utf8map!(*option_array) |
jbe@2 | 63 self.replace(self.utf8map(*option_array)) |
jbe@2 | 64 end |
jbe@2 | 65 def utf8nfd; utf8map( :stable, :decompose); end |
jbe@2 | 66 def utf8nfd!; utf8map!(:stable, :decompose); end |
jbe@2 | 67 def utf8nfc; utf8map( :stable, :compose); end |
jbe@2 | 68 def utf8nfc!; utf8map!(:stable, :compose); end |
jbe@2 | 69 def utf8nfkd; utf8map( :stable, :decompose, :compat); end |
jbe@2 | 70 def utf8nfkd!; utf8map!(:stable, :decompose, :compat); end |
jbe@2 | 71 def utf8nfkc; utf8map( :stable, :compose, :compat); end |
jbe@2 | 72 def utf8nfkc!; utf8map!(:stable, :compose, :compat); end |
jbe@3 | 73 def utf8chars |
jbe@3 | 74 result = self.utf8map(:charbound).split("\377") |
jbe@6 | 75 result.shift if result.first == "" |
jbe@3 | 76 result |
jbe@3 | 77 end |
jbe@2 | 78 def char_ary |
jbe@3 | 79 # depecated, use String#utf8chars instead |
jbe@3 | 80 utf8chars |
jbe@2 | 81 end |
jbe@2 | 82 end |
jbe@2 | 83 |
jbe@2 | 84 module IntegerExtensions |
jbe@2 | 85 def utf8 |
jbe@2 | 86 return Utf8Proc::utf8char(self) |
jbe@2 | 87 end |
jbe@2 | 88 end |
jbe@2 | 89 |
jbe@0 | 90 end |
jbe@0 | 91 |
jbe@2 | 92 |
jbe@0 | 93 class String |
jbe@2 | 94 include(Utf8Proc::StringExtensions) |
jbe@0 | 95 end |
jbe@0 | 96 |
jbe@0 | 97 class Integer |
jbe@2 | 98 include(Utf8Proc::IntegerExtensions) |
jbe@0 | 99 end |
jbe@0 | 100 |