aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-20 11:02:36 +0000
committer_ov4 <ov4@ov4.org>2026-10-20 11:02:36 +0000
commit496c020541d4d35e5800b813b3f8d113a8f2b90b (patch)
tree938a85ff36482af576ecbdd9cd3745ee6d25a336
parenta1ba45b28c94244d2e1c6f00372d51d294cc3edc (diff)
feat(library): add experimental string UCASE overloads
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--pseudocode-lib/README.md2
-rw-r--r--pseudocode-lib/_exp_string.cc12
-rw-r--r--pseudocode-lib/_exp_string.cps10
-rw-r--r--tests/library/exp-string/expected.txt5
-rw-r--r--tests/library/exp-string/notes.md2
-rw-r--r--tests/library/exp-string/program.cps14
6 files changed, 45 insertions, 0 deletions
diff --git a/pseudocode-lib/README.md b/pseudocode-lib/README.md
index 8049ede..bd646ee 100644
--- a/pseudocode-lib/README.md
+++ b/pseudocode-lib/README.md
@@ -26,3 +26,5 @@ The library provides `&`, `_EXP_STRING_NUM_TO_STR` (INTEGER/REAL), `_EXP_STRING_
`_EXP_STRING_MID(S : _EXP_STRING, Start : INTEGER, Count : INTEGER)` returns a new `_EXP_STRING` containing up to Count bytes from the one-based Start position. Starts below 1 clamp to 1; starts beyond the end and nonpositive counts return an empty string. Counts clamp to the remaining bytes. Embedded NUL bytes are preserved.
`_EXP_STRING_LCASE(S : _EXP_STRING)` returns a new `_EXP_STRING` with letters converted to lower case. Its `(Ch : CHAR)` overload returns CHAR, following guide section 5.5. Nonletters and embedded NUL bytes are preserved; the source is unchanged. Use ASCII for predictable case conversion.
+
+`_EXP_STRING_UCASE(S : _EXP_STRING)` returns a new `_EXP_STRING` with letters converted to upper case. Its `(Ch : CHAR)` overload returns CHAR, following guide section 5.5. Nonletters and embedded NUL bytes are preserved; the source is unchanged. Use ASCII for predictable case conversion.
diff --git a/pseudocode-lib/_exp_string.cc b/pseudocode-lib/_exp_string.cc
index 6155319..bd476b8 100644
--- a/pseudocode-lib/_exp_string.cc
+++ b/pseudocode-lib/_exp_string.cc
@@ -101,6 +101,18 @@ char _exp_string_impl_lcase_char(char Ch) {
return static_cast<char>(std::tolower(static_cast<unsigned char>(Ch)));
});
}
+void _exp_string_impl_ucase(void *Target, void *Handle) {
+ checked([&] {
+ text(Target) = text(Handle);
+ for (char &Ch : text(Target))
+ Ch = static_cast<char>(std::toupper(static_cast<unsigned char>(Ch)));
+ });
+}
+char _exp_string_impl_ucase_char(char Ch) {
+ return checked([&] {
+ return static_cast<char>(std::toupper(static_cast<unsigned char>(Ch)));
+ });
+}
void _exp_string_impl_output(void *Handle) {
checked([&] {
const auto &Text = text(Handle);
diff --git a/pseudocode-lib/_exp_string.cps b/pseudocode-lib/_exp_string.cps
index a25b3ef..a56ed04 100644
--- a/pseudocode-lib/_exp_string.cps
+++ b/pseudocode-lib/_exp_string.cps
@@ -19,6 +19,8 @@ EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_right(_EXP_STRING_HANDLE, _EXP_STRI
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_mid(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE, _EXP_STRING_C_INTEGER, _EXP_STRING_C_INTEGER)
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_lcase(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE)
EXTERN "C" EXTERN_FUNCTION _exp_string_impl_lcase_char(C_CHAR) RETURNS C_CHAR
+EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_ucase(_EXP_STRING_HANDLE, _EXP_STRING_HANDLE)
+EXTERN "C" EXTERN_FUNCTION _exp_string_impl_ucase_char(C_CHAR) RETURNS C_CHAR
EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_output(_EXP_STRING_HANDLE)
CLASS _EXP_STRING
@@ -93,3 +95,11 @@ ENDFUNCTION
OVERLOAD FUNCTION _EXP_STRING_LCASE(Ch : CHAR) RETURNS CHAR
RETURN (CHAR)_exp_string_impl_lcase_char((C_CHAR)Ch)
ENDFUNCTION
+OVERLOAD FUNCTION _EXP_STRING_UCASE(S : _EXP_STRING) RETURNS _EXP_STRING
+ DECLARE Result : _EXP_STRING
+ CALL _exp_string_impl_ucase(Result._HANDLE, S._HANDLE)
+ RETURN Result
+ENDFUNCTION
+OVERLOAD FUNCTION _EXP_STRING_UCASE(Ch : CHAR) RETURNS CHAR
+ RETURN (CHAR)_exp_string_impl_ucase_char((C_CHAR)Ch)
+ENDFUNCTION
diff --git a/tests/library/exp-string/expected.txt b/tests/library/exp-string/expected.txt
index f5eda62..b7e35f6 100644
--- a/tests/library/exp-string/expected.txt
+++ b/tests/library/exp-string/expected.txt
@@ -27,3 +27,8 @@ AbC@19
w:w:@
0:8
abc
+ABC@19
+AbC@19
+H:H:@
+0:8
+ABC
diff --git a/tests/library/exp-string/notes.md b/tests/library/exp-string/notes.md
index 47fb6ca..d365dfc 100644
--- a/tests/library/exp-string/notes.md
+++ b/tests/library/exp-string/notes.md
@@ -13,3 +13,5 @@ The added checks use separate procedures to keep generated temporary-object clea
MID positions 2..4 give BCD. The minimum INTEGER start clamps to 1 and gives AB; a maximum count from position 7 gives GH. Empty input, a maximum start, and nonpositive counts give length zero. Four bytes starting at the second of three NULs retain two NULs and AB.
LCASE converts AbC@19 to abc@19 without modifying the source. Its CHAR overload returns CHAR w for W or w and preserves @, as in guide section 5.5. Empty length stays zero; two leading NULs survive conversion and letters after them still become abc.
+
+UCASE converts AbC@19 to ABC@19 without modifying the source. Its CHAR overload returns CHAR H for h or H and preserves @, as in guide section 5.5. Empty length stays zero; two leading NULs survive conversion and letters after them still become ABC.
diff --git a/tests/library/exp-string/program.cps b/tests/library/exp-string/program.cps
index 2e041ec..61a915c 100644
--- a/tests/library/exp-string/program.cps
+++ b/tests/library/exp-string/program.cps
@@ -43,6 +43,7 @@ CALL CheckLeft()
CALL CheckRight()
CALL CheckMid()
CALL CheckLCase()
+CALL CheckUCase()
PROCEDURE CheckLeft()
DECLARE Letters : _EXP_STRING((C_STRING)"ABCDEFGH")
@@ -90,3 +91,16 @@ PROCEDURE CheckLCase()
OUTPUT _EXP_STRING_LENGTH(_EXP_STRING_LCASE(Empty)), ":", _EXP_STRING_LENGTH(_EXP_STRING_LCASE(Nuls & Mixed))
CALL _EXP_STRING_OUTPUT(_EXP_STRING_MID(_EXP_STRING_LCASE(Nuls & Mixed), 3, 3))
ENDPROCEDURE
+
+PROCEDURE CheckUCase()
+ DECLARE Mixed : _EXP_STRING((C_STRING)"AbC@19")
+ DECLARE Empty : _EXP_STRING
+ DECLARE Nuls : _EXP_STRING(2, (C_CHAR)'\0')
+ CALL _EXP_STRING_OUTPUT(_EXP_STRING_UCASE(Mixed))
+ CALL _EXP_STRING_OUTPUT(Mixed)
+ DECLARE Upper : CHAR
+ Upper <- _EXP_STRING_UCASE('h')
+ OUTPUT Upper, ":", _EXP_STRING_UCASE('H'), ":", _EXP_STRING_UCASE('@')
+ OUTPUT _EXP_STRING_LENGTH(_EXP_STRING_UCASE(Empty)), ":", _EXP_STRING_LENGTH(_EXP_STRING_UCASE(Nuls & Mixed))
+ CALL _EXP_STRING_OUTPUT(_EXP_STRING_MID(_EXP_STRING_UCASE(Nuls & Mixed), 3, 3))
+ENDPROCEDURE