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