string_language 0.0.804 → 0.0.805
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/string_helpers.rb +38 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 253cfbc45fdd4f0309f1ae9cbe6bf33963fdfd9d
|
|
4
|
+
data.tar.gz: 817e4b02bff7ab9dfdc82ec165a92c6eac762f09
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f88abec9c7e00f3a46a35872b462e5a80df1183624582503818661fefe85800193ff8c79478084cc7cc27c034c530c5aed3048bf7017098b2f3efba76b8f7ee2
|
|
7
|
+
data.tar.gz: 47620bd58032d3e9b2717cbc230bc5a6a4ab25c1c673a7333ecf428e38dc3db4512d9b437c8389fa3b8a1432959dd260877e8ec29f2835cb334791608b048dda
|
data/lib/string_helpers.rb
CHANGED
|
@@ -35,27 +35,52 @@ module StringHelpers
|
|
|
35
35
|
prefix + middle + suffix
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
# Return stringA with spacing around its interpunction equal to that in StringB
|
|
39
|
+
#
|
|
40
|
+
# @example
|
|
41
|
+
# equalize_interpunction( "A test , succes ! ", "Comma, then exclamation!" ) => "A test, succes!"
|
|
42
|
+
#
|
|
38
43
|
def self.equalize_interpunction stringA, stringB
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
punctuation_marks = "!?.,:;'@|$%^&*-+={()}\/\\\\\#\"\\\[\\\]"
|
|
46
|
+
space_mark_space = /(\s*[#{punctuation_marks}]\s*)/
|
|
47
|
+
get_mark = /\s*([#{punctuation_marks}])\s*/
|
|
48
|
+
|
|
49
|
+
splitA = stringA.split( space_mark_space ) # "'a' ( bla ) (c )" => ["", "'", "a", "' ", "", "( ", "bla )", " (", "c )"]
|
|
50
|
+
splitB = stringB.split( space_mark_space )
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
splitB = stringB.split( regex )
|
|
52
|
+
splitB.each_with_index do |b,indexB|
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
next unless b.match( space_mark_space )
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if a != nil and b != nil and a.match( regex ) and b.match( regex )
|
|
56
|
+
markB = b.gsub( get_mark, '\1' );
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
indexA = corresponding_index( splitA, markB, indexB )
|
|
59
|
+
|
|
60
|
+
splitA[ indexA ] = b unless indexA == nil
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
splitA.join('')
|
|
57
64
|
end
|
|
58
65
|
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
# Return index of string in list that contains given mark. Starting search
|
|
69
|
+
# at start_index. Return nil if search fails.
|
|
70
|
+
def self.corresponding_index( strings, mark, start_index )
|
|
71
|
+
|
|
72
|
+
regexp = /#{Regexp.quote( mark )}/
|
|
73
|
+
|
|
74
|
+
tail = strings[ start_index .. -1 ]
|
|
75
|
+
|
|
76
|
+
return nil if tail == nil
|
|
77
|
+
|
|
78
|
+
tail_index = tail.index { |item| item.match( regexp ) }
|
|
79
|
+
|
|
80
|
+
return nil if tail_index == nil
|
|
81
|
+
|
|
82
|
+
start_index + tail_index
|
|
83
|
+
end
|
|
59
84
|
end
|
|
60
85
|
|
|
61
86
|
# Quick Testing
|
|
@@ -63,6 +88,9 @@ end
|
|
|
63
88
|
a = " Hallo (Dit is een, enigzins, wel (test) 'van' de spacing)!"
|
|
64
89
|
b = " hallo ( Deze was niet goed gespaced, en zelfs , zoals ( test) ' van ' dittum) ! "
|
|
65
90
|
|
|
91
|
+
a = "Choose this item if you want to add videos, slideshows and weblinks to the publication."
|
|
92
|
+
b = "Kies dit item als u video's , slideshows en weblinks wilt toe voegen aan de publicatie ."
|
|
93
|
+
|
|
66
94
|
puts "correct: >#{a}<"
|
|
67
95
|
puts "wrong: >#{b}<"
|
|
68
96
|
puts "test: >#{StringHelpers::equalize( b, a )}<"
|