utf8proc
diff 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)
- 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 |
line diff
1.1 --- a/ruby/gem/lib/utf8proc.rb Wed Jul 25 12:00:00 2007 +0200 1.2 +++ b/ruby/gem/lib/utf8proc.rb Fri May 01 12:00:00 2009 +0200 1.3 @@ -1,1 +1,100 @@ 1.4 -../../utf8proc.rb 1.5 \ No newline at end of file 1.6 +# Copyright (c) 2006-2007 Jan Behrens, FlexiGuided GmbH, Berlin 1.7 +# 1.8 +# Permission is hereby granted, free of charge, to any person obtaining a 1.9 +# copy of this software and associated documentation files (the "Software"), 1.10 +# to deal in the Software without restriction, including without limitation 1.11 +# the rights to use, copy, modify, merge, publish, distribute, sublicense, 1.12 +# and/or sell copies of the Software, and to permit persons to whom the 1.13 +# Software is furnished to do so, subject to the following conditions: 1.14 +# 1.15 +# The above copyright notice and this permission notice shall be included in 1.16 +# all copies or substantial portions of the Software. 1.17 +# 1.18 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1.19 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1.20 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1.21 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1.22 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 1.23 +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 1.24 +# DEALINGS IN THE SOFTWARE. 1.25 + 1.26 + 1.27 +# 1.28 +# File name: ruby/utf8proc.rb 1.29 +# Version: 1.1.1 1.30 +# Last changed: 2006-09-17 1.31 +# 1.32 +# Description: 1.33 +# Part of the ruby wrapper for libutf8proc, which is written in ruby. 1.34 +# 1.35 + 1.36 + 1.37 +require 'utf8proc_native' 1.38 + 1.39 + 1.40 +module Utf8Proc 1.41 + 1.42 + SpecialChars = { 1.43 + :HT => "\x09", 1.44 + :LF => "\x0A", 1.45 + :VT => "\x0B", 1.46 + :FF => "\x0C", 1.47 + :CR => "\x0D", 1.48 + :FS => "\x1C", 1.49 + :GS => "\x1D", 1.50 + :RS => "\x1E", 1.51 + :US => "\x1F", 1.52 + :LS => "\xE2\x80\xA8", 1.53 + :PS => "\xE2\x80\xA9", 1.54 + } 1.55 + 1.56 + module StringExtensions 1.57 + def utf8map(*option_array) 1.58 + options = 0 1.59 + option_array.each do |option| 1.60 + flag = Utf8Proc::Options[option] 1.61 + raise ArgumentError, "Unknown argument given to String#utf8map." unless 1.62 + flag 1.63 + options |= flag 1.64 + end 1.65 + return Utf8Proc::utf8map(self, options) 1.66 + end 1.67 + def utf8map!(*option_array) 1.68 + self.replace(self.utf8map(*option_array)) 1.69 + end 1.70 + def utf8nfd; utf8map( :stable, :decompose); end 1.71 + def utf8nfd!; utf8map!(:stable, :decompose); end 1.72 + def utf8nfc; utf8map( :stable, :compose); end 1.73 + def utf8nfc!; utf8map!(:stable, :compose); end 1.74 + def utf8nfkd; utf8map( :stable, :decompose, :compat); end 1.75 + def utf8nfkd!; utf8map!(:stable, :decompose, :compat); end 1.76 + def utf8nfkc; utf8map( :stable, :compose, :compat); end 1.77 + def utf8nfkc!; utf8map!(:stable, :compose, :compat); end 1.78 + def utf8chars 1.79 + result = self.utf8map(:charbound).split("\377") 1.80 + result.shift if result.first == "" 1.81 + result 1.82 + end 1.83 + def char_ary 1.84 + # depecated, use String#utf8chars instead 1.85 + utf8chars 1.86 + end 1.87 + end 1.88 + 1.89 + module IntegerExtensions 1.90 + def utf8 1.91 + return Utf8Proc::utf8char(self) 1.92 + end 1.93 + end 1.94 + 1.95 +end 1.96 + 1.97 + 1.98 +class String 1.99 + include(Utf8Proc::StringExtensions) 1.100 +end 1.101 + 1.102 +class Integer 1.103 + include(Utf8Proc::IntegerExtensions) 1.104 +end 1.105 +