X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funistr.h;h=26a3e33e458fa42943924eb90dd6709ad7516e47;hb=e8269e90e35140ebb75f39669d39bd021e364105;hp=a645292c064a96726daa788a06a33b2f50a6ed9e;hpb=ac5cf7982cea8a4bb17680b6b9925f301cfa4220;p=gnulib.git diff --git a/lib/unistr.h b/lib/unistr.h index a645292c0..26a3e33e4 100644 --- a/lib/unistr.h +++ b/lib/unistr.h @@ -1,5 +1,5 @@ /* Elementary Unicode string functions. - Copyright (C) 2001-2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2005-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -19,6 +19,9 @@ #include "unitypes.h" +/* Get common macros for C. */ +#include "unused-parameter.h" + /* Get bool. */ #include @@ -81,32 +84,32 @@ extern const uint32_t * /* Convert an UTF-8 string to an UTF-16 string. */ extern uint16_t * u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-8 string to an UCS-4 string. */ extern uint32_t * u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-16 string to an UTF-8 string. */ extern uint8_t * u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-16 string to an UCS-4 string. */ extern uint32_t * u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UCS-4 string to an UTF-8 string. */ extern uint8_t * u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UCS-4 string to an UTF-16 string. */ extern uint16_t * u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Elementary string functions. */ @@ -183,7 +186,8 @@ extern int u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n); # else static inline int -u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n) +u32_mbtouc_unsafe (ucs4_t *puc, + const uint32_t *s, size_t n _GL_UNUSED_PARAMETER) { uint32_t c = *s; @@ -253,7 +257,7 @@ extern int u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n); # else static inline int -u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n) +u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n _GL_UNUSED_PARAMETER) { uint32_t c = *s; @@ -297,12 +301,13 @@ extern int must be specified. */ #ifdef GNULIB_UNISTR_U8_UCTOMB +/* Auxiliary function, also used by u8_chr, u8_strchr, u8_strrchr. */ +extern int + u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n); # if !HAVE_INLINE extern int u8_uctomb (uint8_t *s, ucs4_t uc, int n); # else -extern int - u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n); static inline int u8_uctomb (uint8_t *s, ucs4_t uc, int n) { @@ -318,12 +323,13 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) #endif #ifdef GNULIB_UNISTR_U16_UCTOMB +/* Auxiliary function, also used by u16_chr, u16_strchr, u16_strrchr. */ +extern int + u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n); # if !HAVE_INLINE extern int u16_uctomb (uint16_t *s, ucs4_t uc, int n); # else -extern int - u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n); static inline int u16_uctomb (uint16_t *s, ucs4_t uc, int n) { @@ -349,12 +355,12 @@ u32_uctomb (uint32_t *s, ucs4_t uc, int n) if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { if (n > 0) - { - *s = uc; - return 1; - } + { + *s = uc; + return 1; + } else - return -2; + return -2; } else return -1; @@ -400,6 +406,15 @@ extern int extern int u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n); +/* Compare S1 and S2. */ +/* Similar to the gnulib function memcmp2(). */ +extern int + u8_cmp2 (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2); +extern int + u16_cmp2 (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2); +extern int + u32_cmp2 (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2); + /* Search the string at S for UC. */ /* Similar to memchr(). */ extern uint8_t * @@ -514,8 +529,8 @@ extern uint16_t * extern uint32_t * u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n); -/* Copy no more than N characters of SRC to DEST, returning the address of - the last character written into DEST. */ +/* Copy no more than N units of SRC to DEST. Return a pointer past the last + non-NUL unit written into DEST. */ /* Similar to stpncpy(). */ extern uint8_t * u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n); @@ -551,6 +566,17 @@ extern int extern int u32_strcmp (const uint32_t *s1, const uint32_t *s2); +/* Compare S1 and S2 using the collation rules of the current locale. + Return -1 if S1 < S2, 0 if S1 = S2, 1 if S1 > S2. + Upon failure, set errno and return any value. */ +/* Similar to strcoll(), wcscoll(). */ +extern int + u8_strcoll (const uint8_t *s1, const uint8_t *s2); +extern int + u16_strcoll (const uint16_t *s1, const uint16_t *s2); +extern int + u32_strcoll (const uint32_t *s1, const uint32_t *s2); + /* Compare no more than N units of S1 and S2. */ /* Similar to strncmp(), wcsncmp(). */ extern int