[AD] Unicode (3)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


I'm in the process of unicodifying the setup program and I'm more and more
thinking the current API lacks character manipulation functions.
Suppose you want to get the first 'n' characters (not bytes) of a string.
With the current functions, I don't see anything other than:

size = uoffset(n+1);  /* in bytes */
ustrncpy(s2, s1, MIN(sizeof(s2) - ucwidth(0), size));

I think we should have true character manipulation functions (a true
ustrncpy() for example), distinct from size-aware functions.
So I propose:
   char* ustrcpy(char *, const char *);
   char* ustrncpy(char *, const char *, int n);  (ANSI C behaviour)
   char* ustrzcpy(char *, int size, const char *);
   char* ustrzncpy(char *, int size, const char *, int n);

In this way, the previous code could simply be written:
ustrzncpy(s2, sizeof(s2), s1, n);

This wouldn't bloat the library: we would basically have 1 function
[ustrzncpy()] and 3 wrappers.
Same thing for the ustrcat() family and usprintf().

We would end up with a compliant subset of ANSI C: ustrlen(), ustrcpy(),
ustrncpy(), ustrcat(), ustrncat(), usprintf() and their size-aware
counterparts: ustrsize(), ustrzcpy(), ustrzncpy(), ustrzcat(),
ustrzncat(), uszprintf().

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/