aboutsummaryrefslogtreecommitdiff
path: root/project/dclib/dclib-utf8.c
diff options
context:
space:
mode:
authorWiimm <wiimm@wiimm.de>2022-08-06 16:20:07 +0200
committerWiimm <wiimm@wiimm.de>2022-08-06 16:20:07 +0200
commit7fad9e9383d01cce3ac17176404e1ab4e738736c (patch)
treedf39dd0616554ce9daa138f2e9778c88fbf9ac55 /project/dclib/dclib-utf8.c
parent06ff18cd020779c226f7c25d22016e06b898f303 (diff)
SZS v2.28a.beta2
Diffstat (limited to 'project/dclib/dclib-utf8.c')
-rw-r--r--project/dclib/dclib-utf8.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/project/dclib/dclib-utf8.c b/project/dclib/dclib-utf8.c
index 1ad06ce..e998ac7 100644
--- a/project/dclib/dclib-utf8.c
+++ b/project/dclib/dclib-utf8.c
@@ -1054,6 +1054,45 @@ char * PrintUTF8CharToCircBuf ( u32 code )
}
///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+exmem_t AlignUTF8 ( exmem_dest_t *dest, ccp str, int str_len, int fw, int prec )
+{
+ int slen = str_len < 0
+ ? ScanUTF8Length(str)
+ : ScanUTF8LengthE(str,str+str_len);
+
+ if ( prec >= 0 && slen > prec )
+ slen = prec;
+
+ const int align_left = fw < 0;
+ if (align_left)
+ fw = -fw;
+ if ( fw < slen )
+ fw = slen;
+ int spaces = fw - slen;
+
+ ccp end = SkipUTF8Char(str,slen);
+ const int copy_len = end - str;
+
+ exmem_t res = GetExmemDestBuf(dest,copy_len+spaces);
+ char *buf = (char*)res.data.ptr;
+
+ DASSERT(buf);
+ if (align_left)
+ {
+ memcpy(buf,str,copy_len);
+ memset(buf+copy_len,' ',spaces);
+ }
+ else
+ {
+ memset(buf,' ',spaces);
+ memcpy(buf+spaces,str,copy_len);
+ }
+ return res;
+}
+
+///////////////////////////////////////////////////////////////////////////////
ccp AlignUTF8ToCircBuf ( ccp str, int fw, int prec )
{
@@ -1088,6 +1127,45 @@ ccp AlignUTF8ToCircBuf ( ccp str, int fw, int prec )
}
///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+exmem_t AlignEUTF8 ( exmem_dest_t *dest, ccp str, int str_len, int fw, int prec )
+{
+ int slen = str_len < 0
+ ? ScanUTF8Length(str)
+ : ScanUTF8LengthE(str,str+str_len);
+
+ if ( prec >= 0 && slen > prec )
+ slen = prec;
+
+ const int align_left = fw < 0;
+ if (align_left)
+ fw = -fw;
+ if ( fw < slen )
+ fw = slen;
+ int spaces = fw - slen;
+
+ ccp end = SkipEUTF8Char(str,slen);
+ const int copy_len = end - str;
+
+ exmem_t res = GetExmemDestBuf(dest,copy_len+spaces);
+ char *buf = (char*)res.data.ptr;
+
+ DASSERT(buf);
+ if (align_left)
+ {
+ memcpy(buf,str,copy_len);
+ memset(buf+copy_len,' ',spaces);
+ }
+ else
+ {
+ memset(buf,' ',spaces);
+ memcpy(buf+spaces,str,copy_len);
+ }
+ return res;
+}
+
+///////////////////////////////////////////////////////////////////////////////
ccp AlignEUTF8ToCircBuf ( ccp str, int fw, int prec )
{