jbe@0: ## jbe@0: # Copyright (c) 2006, FlexiGuided GmbH, Berlin, Germany jbe@0: # Author: Jan Behrens jbe@0: # All rights reserved. jbe@0: # jbe@0: # Redistribution and use in source and binary forms, with or without jbe@0: # modification, are permitted provided that the following conditions are jbe@0: # met: jbe@0: # jbe@0: # 1. Redistributions of source code must retain the above copyright jbe@0: # notice, this list of conditions and the following disclaimer. jbe@0: # 2. Redistributions in binary form must reproduce the above copyright jbe@0: # notice, this list of conditions and the following disclaimer in the jbe@0: # documentation and/or other materials provided with the distribution. jbe@0: # 3. Neither the name of the FlexiGuided GmbH nor the names of its jbe@0: # contributors may be used to endorse or promote products derived from jbe@0: # this software without specific prior written permission. jbe@0: # jbe@0: # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS jbe@0: # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT jbe@0: # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A jbe@0: # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER jbe@0: # OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, jbe@0: # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, jbe@0: # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR jbe@0: # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF jbe@0: # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING jbe@0: # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS jbe@0: # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jbe@0: # jbe@0: ## jbe@0: jbe@0: jbe@0: ## jbe@0: # File name: ruby/utf8proc.rb jbe@0: # Version: 0.1 jbe@0: # Last changed: 2006-05-31 jbe@0: # jbe@0: # Description: jbe@0: # Part of the ruby wrapper for libutf8proc, which is written in ruby. jbe@0: ## jbe@0: jbe@0: jbe@0: require 'utf8proc_native' jbe@0: jbe@0: module Utf8Proc jbe@0: SpecialChars = { jbe@0: :HT => "\x09", jbe@0: :LF => "\x0A", jbe@0: :VT => "\x0B", jbe@0: :FF => "\x0C", jbe@0: :CR => "\x0D", jbe@0: :FS => "\x1C", jbe@0: :GS => "\x1D", jbe@0: :RS => "\x1E", jbe@0: :US => "\x1F", jbe@0: :LS => "\xE2\x80\xA8", jbe@0: :PS => "\xE2\x80\xA9", jbe@0: } jbe@0: end jbe@0: jbe@0: class String jbe@0: def utf8map(*option_array) jbe@0: options = 0 jbe@0: option_array.each do |option| jbe@0: flag = Utf8Proc::Options[option] jbe@0: raise ArgumentError, "Unknown argument given to String#utf8map." unless jbe@0: flag jbe@0: options |= flag jbe@0: end jbe@0: return Utf8Proc::utf8map(self, options) jbe@0: end jbe@0: def utf8map!(*option_array) jbe@0: self.replace(self.utf8map(*option_array)) jbe@0: end jbe@0: def utf8nfd; utf8map( :stable); end jbe@0: def utf8nfd!; utf8map!(:stable); end jbe@0: def utf8nfc; utf8map( :stable, :compose); end jbe@0: def utf8nfc!; utf8map!(:stable, :compose); end jbe@0: def utf8nfkd; utf8map( :stable, :compat); end jbe@0: def utf8nfkd!; utf8map!(:stable, :compat); end jbe@0: def utf8nfkc; utf8map( :stable, :compose, :compat); end jbe@0: def utf8nfkc!; utf8map!(:stable, :compose, :compat); end jbe@0: end jbe@0: jbe@0: class Integer jbe@0: def utf8 jbe@0: return Utf8Proc::utf8char(self) jbe@0: end jbe@0: end jbe@0: jbe@0: