Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 48 lines (39 sloc) 0.972 kB
dc95141 @floere + Namespacing in tests
authored
1 # encoding: utf-8
2 #
b611eb7 @floere .
authored
3 # THINK Does it also remove diacritics, like べ to へ?
69b816f @floere + syntax sugared: Search#search_with_text -> Search#search, Search#se…
authored
4 #
d6dbbb4 @floere + everything is now namespaced
authored
5 module Picky
6
b9cd113 @floere + Better documentation for CharacterSubstituters::WestEuropean
authored
7 module CharacterSubstituters
64dab00 @floere + moving to 1.5.3
authored
8
d6dbbb4 @floere + everything is now namespaced
authored
9 # Substitutes Umlauts like
10 # ä, ö, ü => ae, oe, ue.
11 # (and more, see specs)
12 #
77acc31 @floere + Extract Base class for character substituters
authored
13 class WestEuropean < Base
64dab00 @floere + moving to 1.5.3
authored
14
b9cd113 @floere + Better documentation for CharacterSubstituters::WestEuropean
authored
15 # Substitutes occurrences of certain characters
16 # (like Umlauts) with ASCII representations of them.
17 #
18 # Examples:
19 # ä -> ae
20 # Ö -> Oe
21 # ß -> ss
22 # ç -> c
23 #
24 # (See the associated spec for all examples)
25 #
d6dbbb4 @floere + everything is now namespaced
authored
26 def substitute text
59b596c @floere + get rid of ugly ( and), we don't need training wheels anymore
authored
27 trans = @chars.new(text).normalize :kd
64dab00 @floere + moving to 1.5.3
authored
28
b9cd113 @floere + Better documentation for CharacterSubstituters::WestEuropean
authored
29 # Substitute special cases.
d6dbbb4 @floere + everything is now namespaced
authored
30 #
59b596c @floere + get rid of ugly ( and), we don't need training wheels anymore
authored
31 trans.gsub! 'ß', 'ss'
d6dbbb4 @floere + everything is now namespaced
authored
32
b9cd113 @floere + Better documentation for CharacterSubstituters::WestEuropean
authored
33 # Substitute umlauts (of A,O,U,a,o,u).
d6dbbb4 @floere + everything is now namespaced
authored
34 #
59b596c @floere + get rid of ugly ( and), we don't need training wheels anymore
authored
35 trans.gsub! /([AOUaou])\314\210/u, '\1e'
d6dbbb4 @floere + everything is now namespaced
authored
36
b9cd113 @floere + Better documentation for CharacterSubstituters::WestEuropean
authored
37 # Get rid of ecutes, graves etc.
d6dbbb4 @floere + everything is now namespaced
authored
38 #
39 trans.unpack('U*').select { |cp|
40 cp < 0x0300 || cp > 0x035F
59b596c @floere + get rid of ugly ( and), we don't need training wheels anymore
authored
41 }.pack 'U*'
d6dbbb4 @floere + everything is now namespaced
authored
42 end
64dab00 @floere + moving to 1.5.3
authored
43
e817ffd @floere + "european" character substitution
authored
44 end
64dab00 @floere + moving to 1.5.3
authored
45
e817ffd @floere + "european" character substitution
authored
46 end
d6dbbb4 @floere + everything is now namespaced
authored
47
e817ffd @floere + "european" character substitution
authored
48 end
Something went wrong with that request. Please try again.