groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 03/03: Implement .stringdown and .stringup requests.


From: G. Branden Robinson
Subject: [groff] 03/03: Implement .stringdown and .stringup requests.
Date: Sun, 8 Sep 2019 12:13:22 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 41d05cbfac95609586fb447f4e5bfc2d402a241a
Author: G. Branden Robinson <address@hidden>
Date:   Thu Jul 4 01:07:38 2019 +1000

    Implement .stringdown and .stringup requests.
    
    * src/roff/troff/input.cpp: Add .stringdown and .stringup requests.
    * doc/groff.texi: Document them, including example.
    * man/groff_diff.7.man: Same.
    * man/groff.7.man: Document them briefly.
---
 ChangeLog                | 10 ++++++++++
 NEWS                     |  7 +++++++
 doc/groff.texi           | 27 ++++++++++++++++++++++++-
 man/groff.7.man          | 12 +++++++++++
 man/groff_diff.7.man     | 34 +++++++++++++++++++++++++++++++
 src/roff/troff/input.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 141 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3b30f9d..455480b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2019-09-09  G. Branden Robinson <address@hidden>
 
+       Implement .stringdown and .stringup requests.
+
+       * src/roff/troff/input.cpp: Add .stringdown and .stringup
+       requests.
+       * doc/groff.texi: Document them, including example.
+       * man/groff_diff.7.man: Same.
+       * man/groff.7.man: Document them briefly.
+
+2019-09-09  G. Branden Robinson <address@hidden>
+
        Regression-test string case transform feature.
 
        * src/roff/groff/tests/string_case_xform_errors.sh: New test.
diff --git a/NEWS b/NEWS
index 636804e..2f3abcb 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,13 @@ VERSION 1.22.5
 
 Troff
 -----
+o New requests 'stringdown' and 'stringup' are implemented.  These change
+  the string named in their argument by replacing each of its bytes with its
+  lowercase or uppercase version (if any), respectively.  groff special
+  characters (see the groff_char(7) man page) can be used and the output
+  will usually transform in the expected way due to the regular naming
+  convention of the special character escapes.
+
 o On the Latin-1 output device ("groff -T latin1") the output glyph \[oq]
   (opening quote) is now rendered as code point 0x27 (apostrophe) instead of
   0x60 (grave accent).  The ECMA-94 Latin character sets do not define any
diff --git a/doc/groff.texi b/doc/groff.texi
index bcc47cf..3ee915f 100644
--- a/doc/groff.texi
+++ b/doc/groff.texi
@@ -10536,7 +10536,7 @@ beginning of the appended string, and a 
@dfn{compatibility restore}
 input token at the end.
 @endDefreq
 
-Rudimentary string manipulation routines are given with the next two
+Rudimentary string manipulation routines are given with the next several
 requests.
 
 @Defreq {substring, str n1 [@Var{n2}]}
@@ -10578,6 +10578,31 @@ number register @var{reg}.  If @var{reg} doesn't 
exist, it is created.
 @endExample
 @endDefreq
 
+@DefreqList {stringdown, str}
+@DefreqListEndx {stringup, str}
+@cindex case-transforming a string (@code{stringdown}, @code{stringup})
+@cindex uppercasing a string (@code{stringup})
+@cindex lowercasing a string (@code{stringdown})
+@cindex up-casing a string (@code{stringup})
+@cindex down-casing a string (@code{stringdown})
+Change the string named @var{str} by replacing each of its bytes with
+its lowercase (@code{stringdown}) or uppercase (@code{stringup}) version
+(if any).  @code{groff} special characters (see the @cite{groff_char(7)}
+man page) can be used and the output will usually transform in the
+expected way due to the regular naming convention of the special
+character escapes.
+
+@Example
+.ds resume R\['e]sum\['e]\"
+\*[resume]
+.stringdown resume
+\*[resume]
+.stringup resume
+\*[resume]
+    @result{} R�sum� r�sum� R�SUM�
+@endExample
+@endDefreq
+
 @Defreq {rn, xx yy}
 @cindex renaming request (@code{rn})
 @cindex request, renaming (@code{rn})
diff --git a/man/groff.7.man b/man/groff.7.man
index 24f093f..e1a6843 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -2384,6 +2384,18 @@ and sentence space size set to
 of the space width in the current font.
 .
 .TPx
+.REQ .stringdown stringvar
+Replace each byte in the string named
+.I stringvar
+with its lowercase version.
+.
+.TPx
+.REQ .stringup stringvar
+Replace each byte in the string named
+.I stringvar
+with its uppercase version.
+.
+.TPx
 .REQ .sty "n style"
 Associate
 .I style
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index ef31a02..234a37d 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -2168,6 +2168,40 @@ This request is active only if text is justified to both 
margins (using
 .BR .ad\ b ).
 .
 .TP
+.BI .stringdown \~stringvar
+.TQ
+.BI .stringup \~stringvar
+Change the string named
+.I stringvar
+by replacing each of its bytes with its
+lowercase
+.RB ( down )
+or uppercase
+.RB ( up )
+version (if any).
+.
+.I groff
+special characters
+(see
+.IR groff_char (@MAN7EXT@))
+can be used and the output will usually transform in the expected way
+due to the regular naming convention of the special character escapes.
+.
+.IP
+.RS
+.RS
+.EX
+\&.ds resume R\e['e]sum\e['e]\e"
+\e*[resume] \e# Résumé
+\&.stringdown resume
+\e*[resume] \e# résumé
+\&.stringup resume
+\e*[resume] \e# RÉSUMÉ
+.EE
+.RE
+.RE
+.
+.TP
 .BI .sty\  n\ f
 Associate style\~\c
 .I f
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index a1bd8ea..38cf1a3 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -4717,6 +4717,56 @@ void chop_macro()
   skip_line();
 }
 
+enum case_xform_mode { STRING_UPCASE, STRING_DOWNCASE };
+
+// Case-transform each byte of the string argument's contents.
+void do_string_case_transform(case_xform_mode mode)
+{
+  assert((mode == STRING_DOWNCASE) || (mode == STRING_UPCASE));
+  symbol s = get_name(1);
+  if (s.is_null()) {
+    skip_line();
+    return;
+  }
+  request_or_macro *p = lookup_request(s);
+  macro *m = p->to_macro();
+  if (!m) {
+    error("cannot apply string case transformation to a request ('%1')",
+         s.contents());
+    skip_line();
+    return;
+  }
+  string_iterator iter1(*m);
+  macro *mac = new macro;
+  for (int l = 0; l < m->macro::length(); l++) {
+    int nc, c = iter1.get(0);
+    if (c == PUSH_GROFF_MODE
+       || c == PUSH_COMP_MODE
+       || c == POP_GROFFCOMP_MODE)
+      nc = c;
+    else if (c == EOF)
+      break;
+    else
+      if (mode == STRING_DOWNCASE)
+       nc = tolower(c);
+      else
+       nc = toupper(c);
+    mac->append(nc);
+  }
+  request_dictionary.define(s, mac);
+  tok.next();
+}
+
+// Uppercase-transform each byte of the string argument's contents.
+void stringdown_request() {
+  do_string_case_transform(STRING_DOWNCASE);
+}
+
+// Lowercase-transform each byte of the string argument's contents.
+void stringup_request() {
+  do_string_case_transform(STRING_UPCASE);
+}
+
 void substring_request()
 {
   int start;                           // 0, 1, ..., n-1  or  -1, -2, ...
@@ -8213,6 +8263,8 @@ void init_input_requests()
   init_request("shift", shift);
   init_request("so", source);
   init_request("spreadwarn", spreadwarn_request);
+  init_request("stringdown", stringdown_request);
+  init_request("stringup", stringup_request);
   init_request("substring", substring_request);
   init_request("sy", system_request);
   init_request("tag", tag);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]