Lely core libraries  2.3.4
ustring.h
Go to the documentation of this file.
1 
22 #ifndef LELY_UTIL_USTRING_H_
23 #define LELY_UTIL_USTRING_H_
24 
25 #include <lely/libc/uchar.h>
26 
27 #include <assert.h>
28 #include <stddef.h>
29 
30 #ifndef LELY_UTIL_USTRING_INLINE
31 #define LELY_UTIL_USTRING_INLINE static inline
32 #endif
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
46 LELY_UTIL_USTRING_INLINE size_t str16len(const char16_t *s);
47 
61 LELY_UTIL_USTRING_INLINE char16_t *str16ncpy(
62  char16_t *dst, const char16_t *src, size_t n);
63 
74 LELY_UTIL_USTRING_INLINE int str16ncmp(
75  const char16_t *s1, const char16_t *s2, size_t n);
76 
77 LELY_UTIL_USTRING_INLINE size_t
78 str16len(const char16_t *s)
79 {
80  const char16_t *cp = s;
81  while (*cp != 0)
82  cp++;
83 
84  return cp - s;
85 }
86 
87 LELY_UTIL_USTRING_INLINE char16_t *
88 str16ncpy(char16_t *dst, const char16_t *src, size_t n)
89 {
90  char16_t *cp = dst;
91  for (; (n != 0) && (*src != 0); n--, cp++, src++)
92  *cp = *src;
93  for (; n != 0; n--)
94  *cp++ = 0;
95 
96  return dst;
97 }
98 
99 LELY_UTIL_USTRING_INLINE int
100 str16ncmp(const char16_t *s1, const char16_t *s2, size_t n)
101 {
102  for (; n != 0; n--, s1++, s2++) {
103  const int cmp = *s1 - *s2;
104  if ((cmp != 0) || (*s1 == 0))
105  return cmp;
106  }
107  return 0;
108 }
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 #endif // !LELY_UTIL_USTRING_H_
str16ncmp
int str16ncmp(const char16_t *s1, const char16_t *s2, size_t n)
Compares two (16-bit) Unicode strings.
Definition: ustring.h:100
str16ncpy
char16_t * str16ncpy(char16_t *dst, const char16_t *src, size_t n)
Copies n (16-bit) Unicode characters from the string at src to dst.
Definition: ustring.h:88
str16len
size_t str16len(const char16_t *s)
Returns the number of (16-bit) Unicode characters, excluding the terminating null bytes,...
Definition: ustring.h:78
uchar.h
stddef.h