Don't instantiate objects where constants can be used.
This commit is contained in:
parent
66bb686f4b
commit
5768d3188a
1 changed files with 16 additions and 15 deletions
|
|
@ -5,6 +5,20 @@
|
|||
# Deeply inspired by https://gitorious.org/statusnet/mainline/blobs/master/plugins/DirectionDetector/DirectionDetectorPlugin.php
|
||||
|
||||
class String
|
||||
RTL_RANGES = [
|
||||
[1536, 1791], # arabic, persian, urdu, kurdish, ...
|
||||
[65136, 65279], # arabic peresent 2
|
||||
[64336, 65023], # arabic peresent 1
|
||||
[1424, 1535], # hebrew
|
||||
[64256, 64335], # hebrew peresent
|
||||
[1792, 1871], # syriac
|
||||
[1920, 1983], # thaana
|
||||
[1984, 2047], # nko
|
||||
[11568, 11647] # tifinagh
|
||||
]
|
||||
RTL_CLEANER_REGEXES = [ /@[^ ]+|#[^ ]+/u, # mention, tag
|
||||
/^RT[: ]{1}| RT | RT: |[♺♻:]/u # retweet
|
||||
]
|
||||
|
||||
def is_rtl?
|
||||
return false if self.strip.empty?
|
||||
|
|
@ -23,9 +37,7 @@ class String
|
|||
# Diaspora specific
|
||||
def cleaned_is_rtl?
|
||||
string = String.new(self)
|
||||
[ /@[^ ]+|#[^ ]+/u, # mention, tag
|
||||
/^RT[: ]{1}| RT | RT: |[♺♻:]/u # retweet
|
||||
].each do |cleaner|
|
||||
RTL_CLEANER_REGEXES.each do |cleaner|
|
||||
string.gsub!(cleaner, '')
|
||||
end
|
||||
string.is_rtl?
|
||||
|
|
@ -34,18 +46,7 @@ class String
|
|||
def starts_with_rtl_char?(string = self)
|
||||
return false if string.strip.empty?
|
||||
char = string.strip.unpack('U*').first
|
||||
limits = [
|
||||
[1536, 1791], # arabic, persian, urdu, kurdish, ...
|
||||
[65136, 65279], # arabic peresent 2
|
||||
[64336, 65023], # arabic peresent 1
|
||||
[1424, 1535], # hebrew
|
||||
[64256, 64335], # hebrew peresent
|
||||
[1792, 1871], # syriac
|
||||
[1920, 1983], # thaana
|
||||
[1984, 2047], # nko
|
||||
[11568, 11647] # tifinagh
|
||||
]
|
||||
limits.each do |limit|
|
||||
RTL_RANGES.each do |limit|
|
||||
return true if char >= limit[0] && char <= limit[1]
|
||||
end
|
||||
return false
|
||||
|
|
|
|||
Loading…
Reference in a new issue