Class: UniPropUtils::FileRegexp

Inherits:
Object
  • Object
show all
Defined in:
lib/uniprop/utils.rb

Class Method Summary collapse

Class Method Details

.matched_positions(text, regexp) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/uniprop/utils.rb', line 192

def matched_positions(text, regexp)
  mp = []
  m = text.match(regexp)

  col_cnt = 0
  while m
    position = {}
    
    position[:match_data] = m
    col_cnt += m.pre_match.count("\n")
    position[:begin_col] = col_cnt
    col_cnt += m[0].count("\n")
    position[:end_col] = col_cnt
    position[:begin_point] = m.begin(0) - m.pre_match.rindex("\n").to_i() - 1
    position[:end_point] = position[:begin_point] + m[0].size - m[0].rindex("\n").to_i() -1
    
    mp << position
    text = m.post_match
    m = text.match(regexp)
  end
  
  mp
end