Update of bug #60802 (project groff): Status: None => Need Info Assigned to: None => gbranden
_______________________________________________________ Follow-up Comment #3: Hi Jim, Thank you! This is really helpful. It's already led me to a preliminary patch that resolves every test case you presented, with one exception which you seem to have anticipated. The use of negative indices to count backward from the end of the string is a common semantic in programming languages that support array slicing (which is basically what .substring does). I'm not sure the groff community will be willing to give up that feature, and in-tree groff code already uses it. Anyway, with my very first stab at a patch to src/roff/troff/input.cpp, I've got the following output: $ bash ./substring_test_revised.bash Exit status was 1 --- Pick a single character from non-empty --- .substring 'abc' 0 0 -> 'a' (OK) .substring 'abc' 1 1 -> 'b' (OK) .substring 'abc' 2 2 -> 'c' (OK) --- Pick multiple characters from non-empty --- .substring 'abcd' 0 1 -> 'ab' (OK) .substring 'abcd' 1 1 -> 'b' (OK) .substring 'abcd' 0 3 -> 'abcd' (OK) .substring 'abcd' 1 3 -> 'bcd' (OK) .substring 'abcd' 2 3 -> 'cd' (OK) .substring 'abcd' 3 3 -> 'd' (OK) --- Omit n2 with non-empty input and non-empty result --- .substring 'abc' 0 -> 'abc' (OK) .substring 'abc' 1 -> 'bc' (OK) .substring 'abc' 2 -> 'c' (OK) .substring 'a' 0 -> 'a' (OK) --- Specify empty substring with n2==(n1-1) --- .substring 'abcd' 3 2 -> '' (OK) .substring 'abcd' 2 1 -> '' (OK) .substring 'abcd' 1 0 -> '' (OK) ERROR: .substring 'abcd' 0 -1 yielded 'abcd', EXPECTED '' --- Specify empty substring with n1==length and n2 omitted --- troff: ./substring_test_revised.bash:78: warning: start and end index of substring out of range .substring 'abcd' 4 -> '' (OK) troff: ./substring_test_revised.bash:79: warning: start and end index of substring out of range .substring 'abc' 3 -> '' (OK) troff: ./substring_test_revised.bash:80: warning: start and end index of substring out of range .substring 'ab' 2 -> '' (OK) troff: ./substring_test_revised.bash:81: warning: start and end index of substring out of range .substring 'a' 1 -> '' (OK) troff: ./substring_test_revised.bash:82: warning: start and end index of substring out of range .substring '' 0 -> '' (OK) Aborting, got 1 errors. Also, I don't think we should talk about "undefined behavior" in our documentation. We are implementors, not a standards body, so we should document how .substring works. It's okay for us to say "it is an error if...", and our Texinfo manual already has language like this in many places. What do you think? _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?60802> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/