utf8proc

diff ruby/utf8proc.rb @ 0:a0368662434c

Version 0.1
author jbe
date Fri Jun 02 12:00:00 2006 +0200 (2006-06-02)
parents
children 61a89ecc2fb9
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ruby/utf8proc.rb	Fri Jun 02 12:00:00 2006 +0200
     1.3 @@ -0,0 +1,92 @@
     1.4 +##
     1.5 + #  Copyright (c) 2006, FlexiGuided GmbH, Berlin, Germany
     1.6 + #  Author: Jan Behrens <jan.behrens@flexiguided.de>
     1.7 + #  All rights reserved.
     1.8 + #
     1.9 + #  Redistribution and use in source and binary forms, with or without
    1.10 + #  modification, are permitted provided that the following conditions are
    1.11 + #  met:
    1.12 + #
    1.13 + #  1. Redistributions of source code must retain the above copyright
    1.14 + #     notice, this list of conditions and the following disclaimer.
    1.15 + #  2. Redistributions in binary form must reproduce the above copyright
    1.16 + #     notice, this list of conditions and the following disclaimer in the
    1.17 + #     documentation and/or other materials provided with the distribution.
    1.18 + #  3. Neither the name of the FlexiGuided GmbH nor the names of its
    1.19 + #     contributors may be used to endorse or promote products derived from
    1.20 + #     this software without specific prior written permission.
    1.21 + #
    1.22 + #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.23 + #  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.24 + #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    1.25 + #  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
    1.26 + #  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.27 + #  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.28 + #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.29 + #  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.30 + #  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.31 + #  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    1.32 + #  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.33 + #
    1.34 + ##
    1.35 + 
    1.36 +
    1.37 +##
    1.38 + #  File name:    ruby/utf8proc.rb
    1.39 + #  Version:      0.1
    1.40 + #  Last changed: 2006-05-31
    1.41 + #
    1.42 + #  Description:
    1.43 + #  Part of the ruby wrapper for libutf8proc, which is written in ruby.
    1.44 + ##
    1.45 +
    1.46 +
    1.47 +require 'utf8proc_native'
    1.48 +
    1.49 +module Utf8Proc
    1.50 +  SpecialChars = {
    1.51 +    :HT => "\x09",
    1.52 +    :LF => "\x0A",
    1.53 +    :VT => "\x0B",
    1.54 +    :FF => "\x0C",
    1.55 +    :CR => "\x0D",
    1.56 +    :FS => "\x1C",
    1.57 +    :GS => "\x1D",
    1.58 +    :RS => "\x1E",
    1.59 +    :US => "\x1F",
    1.60 +    :LS => "\xE2\x80\xA8",
    1.61 +    :PS => "\xE2\x80\xA9",
    1.62 +  }
    1.63 +end
    1.64 +
    1.65 +class String
    1.66 +  def utf8map(*option_array)
    1.67 +    options = 0
    1.68 +    option_array.each do |option|
    1.69 +      flag = Utf8Proc::Options[option]
    1.70 +      raise ArgumentError, "Unknown argument given to String#utf8map." unless
    1.71 +        flag
    1.72 +      options |= flag
    1.73 +    end
    1.74 +    return Utf8Proc::utf8map(self, options)
    1.75 +  end
    1.76 +  def utf8map!(*option_array)
    1.77 +    self.replace(self.utf8map(*option_array))
    1.78 +  end
    1.79 +  def utf8nfd;   utf8map( :stable); end
    1.80 +  def utf8nfd!;  utf8map!(:stable); end
    1.81 +  def utf8nfc;   utf8map( :stable, :compose); end
    1.82 +  def utf8nfc!;  utf8map!(:stable, :compose); end
    1.83 +  def utf8nfkd;  utf8map( :stable, :compat); end
    1.84 +  def utf8nfkd!; utf8map!(:stable, :compat); end
    1.85 +  def utf8nfkc;  utf8map( :stable, :compose, :compat); end
    1.86 +  def utf8nfkc!; utf8map!(:stable, :compose, :compat); end
    1.87 +end
    1.88 +
    1.89 +class Integer
    1.90 +  def utf8
    1.91 +    return Utf8Proc::utf8char(self)
    1.92 +  end
    1.93 +end
    1.94 +
    1.95 +

Impressum / About Us