From 8975d167c849f54664be8d5da418cd909694d26f Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 20 Oct 2026 11:04:06 +0000 Subject: feat(library): add experimental string CHR function Co-Authored-By: Claude Opus 5.5 --- pseudocode-lib/README.md | 2 ++ pseudocode-lib/_exp_string.cc | 5 +++++ pseudocode-lib/_exp_string.cps | 6 ++++++ 3 files changed, 13 insertions(+) (limited to 'pseudocode-lib') diff --git a/pseudocode-lib/README.md b/pseudocode-lib/README.md index 665e2ed..90fab0e 100644 --- a/pseudocode-lib/README.md +++ b/pseudocode-lib/README.md @@ -30,3 +30,5 @@ The library provides `&`, `_EXP_STRING_NUM_TO_STR` (INTEGER/REAL), `_EXP_STRING_ `_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. `_EXP_STRING_ASC(S : _EXP_STRING)` returns the unsigned code of the first byte as INTEGER, or 0 for an empty string. Its `(Ch : CHAR)` overload returns the unsigned byte code of Ch. For ASCII characters this is the ASCII code. + +`_EXP_STRING_CHR(Code : INTEGER)` returns a new `_EXP_STRING` containing the low eight bits of Code as one byte. Unlike built-in STRING, `_EXP_STRING` preserves NUL: `_EXP_STRING_CHR(0)` has length 1. diff --git a/pseudocode-lib/_exp_string.cc b/pseudocode-lib/_exp_string.cc index 6a17f74..ae53ac1 100644 --- a/pseudocode-lib/_exp_string.cc +++ b/pseudocode-lib/_exp_string.cc @@ -122,6 +122,11 @@ long long _exp_string_impl_asc(void *Handle) { long long _exp_string_impl_asc_char(char Ch) { return checked([&]() -> long long { return static_cast(Ch); }); } +void _exp_string_impl_chr(void *Target, long long Code) { + checked([&] { + text(Target).assign(1, static_cast(static_cast(Code))); + }); +} 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 a4d95d6..965a251 100644 --- a/pseudocode-lib/_exp_string.cps +++ b/pseudocode-lib/_exp_string.cps @@ -23,6 +23,7 @@ EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_ucase(_EXP_STRING_HANDLE, _EXP_STRI EXTERN "C" EXTERN_FUNCTION _exp_string_impl_ucase_char(C_CHAR) RETURNS C_CHAR EXTERN "C" EXTERN_FUNCTION _exp_string_impl_asc(_EXP_STRING_HANDLE) RETURNS _EXP_STRING_C_INTEGER EXTERN "C" EXTERN_FUNCTION _exp_string_impl_asc_char(C_CHAR) RETURNS _EXP_STRING_C_INTEGER +EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_chr(_EXP_STRING_HANDLE, _EXP_STRING_C_INTEGER) EXTERN "C" EXTERN_PROCEDURE _exp_string_impl_output(_EXP_STRING_HANDLE) CLASS _EXP_STRING @@ -111,3 +112,8 @@ ENDFUNCTION OVERLOAD FUNCTION _EXP_STRING_ASC(Ch : CHAR) RETURNS INTEGER RETURN (INTEGER)_exp_string_impl_asc_char((C_CHAR)Ch) ENDFUNCTION +FUNCTION _EXP_STRING_CHR(Code : INTEGER) RETURNS _EXP_STRING + DECLARE Result : _EXP_STRING + CALL _exp_string_impl_chr(Result._HANDLE, (_EXP_STRING_C_INTEGER)Code) + RETURN Result +ENDFUNCTION -- cgit v1.3.1-4-g156e