lib/regexp-examples/backreferences.rb in regexp-examples-0.5.3 vs lib/regexp-examples/backreferences.rb in regexp-examples-0.5.4
- old
+ new
@@ -17,12 +17,19 @@
private
def find_backref_for(full_example, group_id)
full_example.all_subgroups.detect do |subgroup|
subgroup.group_id == group_id
- end || raise(RegexpExamples::BackrefNotFound)
- # TODO: Regex like /\10/ should match the octal representation of their character code,
- # if there is no nth grouped subexpression. For example, `/\10/.examples` should return `["\x08"]`
+ end || octal_char_for(group_id)
+ end
+
+ def octal_char_for(octal_chars)
+ # For octal characters in the range \10 - \177
+ if octal_chars =~ /\A[01]?[0-7]{1,2}\z/ && octal_chars.to_i >= 10
+ Integer(octal_chars, 8).chr
+ else
+ raise(RegexpExamples::BackrefNotFound)
+ end
end
end
end