jbe@9: # Copyright (c) 2006-2007 Jan Behrens, FlexiGuided GmbH, Berlin jbe@9: # jbe@9: # Permission is hereby granted, free of charge, to any person obtaining a jbe@9: # copy of this software and associated documentation files (the "Software"), jbe@9: # to deal in the Software without restriction, including without limitation jbe@9: # the rights to use, copy, modify, merge, publish, distribute, sublicense, jbe@9: # and/or sell copies of the Software, and to permit persons to whom the jbe@9: # Software is furnished to do so, subject to the following conditions: jbe@9: # jbe@9: # The above copyright notice and this permission notice shall be included in jbe@9: # all copies or substantial portions of the Software. jbe@9: # jbe@9: # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jbe@9: # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jbe@9: # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jbe@9: # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER jbe@9: # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING jbe@9: # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER jbe@9: # DEALINGS IN THE SOFTWARE. jbe@9: jbe@9: jbe@9: # jbe@9: # File name: ruby/utf8proc.rb jbe@9: # Version: 1.1.1 jbe@9: # Last changed: 2006-09-17 jbe@9: # jbe@9: # Description: jbe@9: # Part of the ruby wrapper for libutf8proc, which is written in ruby. jbe@9: # jbe@9: jbe@9: jbe@9: require 'utf8proc_native' jbe@9: jbe@9: jbe@9: module Utf8Proc jbe@9: jbe@9: SpecialChars = { jbe@9: :HT => "\x09", jbe@9: :LF => "\x0A", jbe@9: :VT => "\x0B", jbe@9: :FF => "\x0C", jbe@9: :CR => "\x0D", jbe@9: :FS => "\x1C", jbe@9: :GS => "\x1D", jbe@9: :RS => "\x1E", jbe@9: :US => "\x1F", jbe@9: :LS => "\xE2\x80\xA8", jbe@9: :PS => "\xE2\x80\xA9", jbe@9: } jbe@9: jbe@9: module StringExtensions jbe@9: def utf8map(*option_array) jbe@9: options = 0 jbe@9: option_array.each do |option| jbe@9: flag = Utf8Proc::Options[option] jbe@9: raise ArgumentError, "Unknown argument given to String#utf8map." unless jbe@9: flag jbe@9: options |= flag jbe@9: end jbe@9: return Utf8Proc::utf8map(self, options) jbe@9: end jbe@9: def utf8map!(*option_array) jbe@9: self.replace(self.utf8map(*option_array)) jbe@9: end jbe@9: def utf8nfd; utf8map( :stable, :decompose); end jbe@9: def utf8nfd!; utf8map!(:stable, :decompose); end jbe@9: def utf8nfc; utf8map( :stable, :compose); end jbe@9: def utf8nfc!; utf8map!(:stable, :compose); end jbe@9: def utf8nfkd; utf8map( :stable, :decompose, :compat); end jbe@9: def utf8nfkd!; utf8map!(:stable, :decompose, :compat); end jbe@9: def utf8nfkc; utf8map( :stable, :compose, :compat); end jbe@9: def utf8nfkc!; utf8map!(:stable, :compose, :compat); end jbe@9: def utf8chars jbe@9: result = self.utf8map(:charbound).split("\377") jbe@9: result.shift if result.first == "" jbe@9: result jbe@9: end jbe@9: def char_ary jbe@9: # depecated, use String#utf8chars instead jbe@9: utf8chars jbe@9: end jbe@9: end jbe@9: jbe@9: module IntegerExtensions jbe@9: def utf8 jbe@9: return Utf8Proc::utf8char(self) jbe@9: end jbe@9: end jbe@9: jbe@9: end jbe@9: jbe@9: jbe@9: class String jbe@9: include(Utf8Proc::StringExtensions) jbe@9: end jbe@9: jbe@9: class Integer jbe@9: include(Utf8Proc::IntegerExtensions) jbe@9: end jbe@9: