utf8proc

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

Impressum / About Us