SVN revision: 58448
This commit is contained in:
Carsten Haitzler 2011-04-07 13:15:31 +00:00
parent af1bdf3525
commit d2b654d777
2 changed files with 99 additions and 87 deletions

View File

@ -39,33 +39,132 @@ typedef uint32_t Eina_Unicode;
typedef unsigned int Eina_Unicode; typedef unsigned int Eina_Unicode;
#endif #endif
/**
* @brief Same as the standard strlen just with Eina_Unicode instead of char.
*/
EAPI extern const Eina_Unicode *EINA_UNICODE_EMPTY_STRING; EAPI extern const Eina_Unicode *EINA_UNICODE_EMPTY_STRING;
EAPI size_t eina_unicode_strlen(const Eina_Unicode *ustr) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; EAPI size_t eina_unicode_strlen(const Eina_Unicode *ustr) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
/**
* @brief Returns the length of a Eina_Unicode string, up to a limit.
*
* This function returns the number of characters in string, up to a maximum
* of n. If the terminating character is not found in the string, it returns
* n.
*
* @param ustr String to search
* @param n Max length to search
* @return Number of characters or n.
*/
EAPI size_t eina_unicode_strnlen(const Eina_Unicode *ustr, int n) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; EAPI size_t eina_unicode_strnlen(const Eina_Unicode *ustr, int n) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE;
/**
* @brief Same as the standard strdup just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode *eina_unicode_strdup(const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; EAPI Eina_Unicode *eina_unicode_strdup(const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
/**
* @brief Same as strdup but cuts on n. Assumes n < len
* @since 1.1.0
*/
EAPI Eina_Unicode *eina_unicode_strndup(const Eina_Unicode *text, size_t n) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; EAPI Eina_Unicode *eina_unicode_strndup(const Eina_Unicode *text, size_t n) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
/**
* @brief Same as the standard strcmp just with Eina_Unicode instead of char.
*/
EAPI int eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE; EAPI int eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;
/**
* @brief Same as the standard strcpy just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode *eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) EINA_ARG_NONNULL(1, 2); EAPI Eina_Unicode *eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) EINA_ARG_NONNULL(1, 2);
/**
* @brief Same as the standard strstr just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode *eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE; EAPI Eina_Unicode *eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;
/**
* @brief Same as the standard strncpy just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode *eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n) EINA_ARG_NONNULL(1, 2); EAPI Eina_Unicode *eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n) EINA_ARG_NONNULL(1, 2);
/**
* @see eina_str_escape()
*/
EAPI Eina_Unicode *eina_unicode_escape(const Eina_Unicode *str) EINA_ARG_NONNULL(1) EINA_MALLOC EINA_WARN_UNUSED_RESULT; EAPI Eina_Unicode *eina_unicode_escape(const Eina_Unicode *str) EINA_ARG_NONNULL(1) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
/* UTF-8 Handling */ /* UTF-8 Handling */
/**
* Reads UTF8 bytes from @buf, starting at *@index and returns
* the decoded code point at iindex offset, and advances iindex
* to the next code point after this. iindex is always advanced,
* unless if the advancement is after the NULL.
* On error: return a codepoint between DC80 to DCFF where the low 8 bits
* are the byte's value.
*
* @param buf the string
* @param iindex the index to look at and return by.
* @return the codepoint found.
* @since 1.1.0
*/
EAPI Eina_Unicode eina_unicode_utf8_get_next(const char *buf, int *iindex) EINA_ARG_NONNULL(1, 2); EAPI Eina_Unicode eina_unicode_utf8_get_next(const char *buf, int *iindex) EINA_ARG_NONNULL(1, 2);
/**
* Reads UTF8 bytes from @buf, starting at *@iindex and returns
* the decoded code point at iindex offset, and moves iindex
* to the previous code point. iindex is always moved, as long
* as it's not past the start of the string.
* On error: return a codepoint between DC80 to DCFF where the low 8 bits
* are the byte's value.
*
* @param buf the string
* @param iindex the index to look at and return by.
* @return the codepoint found.
* @since 1.1.0
*/
EAPI Eina_Unicode eina_unicode_utf8_get_prev(const char *buf, int *iindex) EINA_ARG_NONNULL(1, 2); EAPI Eina_Unicode eina_unicode_utf8_get_prev(const char *buf, int *iindex) EINA_ARG_NONNULL(1, 2);
/**
* Returns the number of unicode characters in the string. That is,
* the number of Eina_Unicodes it'll take to store this string in
* an Eina_Unicode string.
*
* @param buf the string
* @return the number of unicode characters (not bytes) in the string
* @since 1.1.0
*/
EAPI int eina_unicode_utf8_get_len(const char *buf) EINA_ARG_NONNULL(1); EAPI int eina_unicode_utf8_get_len(const char *buf) EINA_ARG_NONNULL(1);
/**
* Converts a utf-8 string to a newly allocated Eina_Unicode string.
*
* @param utf the string in utf-8
* @param _len the length of the returned Eina_Unicode string.
* @return the newly allocated Eina_Unicode string.
* @since 1.1.0
*/
EAPI Eina_Unicode *eina_unicode_utf8_to_unicode(const char *utf, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; EAPI Eina_Unicode *eina_unicode_utf8_to_unicode(const char *utf, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
/**
* Converts an Eina_Unicode string to a newly allocated utf-8 string.
*
* @param uni the Eina_Unicode string
* @param _len the length byte length of the return utf8 string.
* @return the newly allocated utf-8 string.
* @since 1.1.0
*/
EAPI char * eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; EAPI char * eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
/** /**

View File

@ -27,9 +27,6 @@
/* Maybe I'm too tired, but this is the only thing that actually worked. */ /* Maybe I'm too tired, but this is the only thing that actually worked. */
const Eina_Unicode _EINA_UNICODE_EMPTY_STRING[1] = {0}; const Eina_Unicode _EINA_UNICODE_EMPTY_STRING[1] = {0};
EAPI const Eina_Unicode *EINA_UNICODE_EMPTY_STRING = _EINA_UNICODE_EMPTY_STRING; EAPI const Eina_Unicode *EINA_UNICODE_EMPTY_STRING = _EINA_UNICODE_EMPTY_STRING;
/**
* @brief Same as the standard strcmp just with Eina_Unicode instead of char.
*/
EAPI int EAPI int
eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b)
{ {
@ -43,9 +40,6 @@ eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b)
return 1; return 1;
} }
/**
* @brief Same as the standard strcpy just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source)
{ {
@ -57,9 +51,6 @@ eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source)
return ret; return ret;
} }
/**
* @brief Same as the standard strncpy just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n) eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n)
{ {
@ -72,9 +63,6 @@ eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n)
return ret; return ret;
} }
/**
* @brief Same as the standard strlen just with Eina_Unicode instead of char.
*/
EAPI size_t EAPI size_t
eina_unicode_strlen(const Eina_Unicode *ustr) eina_unicode_strlen(const Eina_Unicode *ustr)
{ {
@ -84,17 +72,6 @@ eina_unicode_strlen(const Eina_Unicode *ustr)
return end - ustr; return end - ustr;
} }
/**
* @brief Returns the length of a Eina_Unicode string, up to a limit.
*
* This function returns the number of characters in string, up to a maximum
* of n. If the terminating character is not found in the string, it returns
* n.
*
* @param ustr String to search
* @param n Max length to search
* @return Number of characters or n.
*/
EAPI size_t EAPI size_t
eina_unicode_strnlen(const Eina_Unicode *ustr, int n) eina_unicode_strnlen(const Eina_Unicode *ustr, int n)
{ {
@ -108,10 +85,6 @@ eina_unicode_strnlen(const Eina_Unicode *ustr, int n)
/**
* @brief Same as strdup but cuts on n. Assumes n < len
* @since 1.1.0
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_strndup(const Eina_Unicode *text, size_t n) eina_unicode_strndup(const Eina_Unicode *text, size_t n)
{ {
@ -123,9 +96,6 @@ eina_unicode_strndup(const Eina_Unicode *text, size_t n)
return ustr; return ustr;
} }
/**
* @brief Same as the standard strdup just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_strdup(const Eina_Unicode *text) eina_unicode_strdup(const Eina_Unicode *text)
{ {
@ -135,9 +105,6 @@ eina_unicode_strdup(const Eina_Unicode *text)
return eina_unicode_strndup(text, len); return eina_unicode_strndup(text, len);
} }
/**
* @brief Same as the standard strstr just with Eina_Unicode instead of char.
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle) eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle)
{ {
@ -158,9 +125,6 @@ eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle)
return NULL; return NULL;
} }
/**
* @see eina_str_escape()
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_escape(const Eina_Unicode *str) eina_unicode_escape(const Eina_Unicode *str)
{ {
@ -194,19 +158,6 @@ eina_unicode_escape(const Eina_Unicode *str)
#define IS_INVALID_BYTE(x) ((x == 192) || (x == 193) || (x >= 245)) #define IS_INVALID_BYTE(x) ((x == 192) || (x == 193) || (x >= 245))
#define IS_CONTINUATION_BYTE(x) ((x & 0xC0) == 0x80) #define IS_CONTINUATION_BYTE(x) ((x & 0xC0) == 0x80)
/**
* Reads UTF8 bytes from @buf, starting at *@index and returns
* the decoded code point at iindex offset, and advances iindex
* to the next code point after this. iindex is always advanced,
* unless if the advancement is after the NULL.
* On error: return a codepoint between DC80 to DCFF where the low 8 bits
* are the byte's value.
*
* @param buf the string
* @param iindex the index to look at and return by.
* @return the codepoint found.
* @since 1.1.0
*/
EAPI Eina_Unicode EAPI Eina_Unicode
eina_unicode_utf8_get_next(const char *buf, int *iindex) eina_unicode_utf8_get_next(const char *buf, int *iindex)
{ {
@ -312,19 +263,6 @@ error:
return ERROR_REPLACEMENT_BASE | d; return ERROR_REPLACEMENT_BASE | d;
} }
/**
* Reads UTF8 bytes from @buf, starting at *@iindex and returns
* the decoded code point at iindex offset, and moves iindex
* to the previous code point. iindex is always moved, as long
* as it's not past the start of the string.
* On error: return a codepoint between DC80 to DCFF where the low 8 bits
* are the byte's value.
*
* @param buf the string
* @param iindex the index to look at and return by.
* @return the codepoint found.
* @since 1.1.0
*/
EAPI Eina_Unicode EAPI Eina_Unicode
eina_unicode_utf8_get_prev(const char *buf, int *iindex) eina_unicode_utf8_get_prev(const char *buf, int *iindex)
{ {
@ -348,15 +286,6 @@ eina_unicode_utf8_get_prev(const char *buf, int *iindex)
return r; return r;
} }
/**
* Returns the number of unicode characters in the string. That is,
* the number of Eina_Unicodes it'll take to store this string in
* an Eina_Unicode string.
*
* @param buf the string
* @return the number of unicode characters (not bytes) in the string
* @since 1.1.0
*/
EAPI int EAPI int
eina_unicode_utf8_get_len(const char *buf) eina_unicode_utf8_get_len(const char *buf)
{ {
@ -369,14 +298,6 @@ eina_unicode_utf8_get_len(const char *buf)
return len; return len;
} }
/**
* Converts a utf-8 string to a newly allocated Eina_Unicode string.
*
* @param utf the string in utf-8
* @param _len the length of the returned Eina_Unicode string.
* @return the newly allocated Eina_Unicode string.
* @since 1.1.0
*/
EAPI Eina_Unicode * EAPI Eina_Unicode *
eina_unicode_utf8_to_unicode(const char *utf, int *_len) eina_unicode_utf8_to_unicode(const char *utf, int *_len)
{ {
@ -399,14 +320,6 @@ eina_unicode_utf8_to_unicode(const char *utf, int *_len)
return buf; return buf;
} }
/**
* Converts an Eina_Unicode string to a newly allocated utf-8 string.
*
* @param uni the Eina_Unicode string
* @param _len the length byte length of the return utf8 string.
* @return the newly allocated utf-8 string.
* @since 1.1.0
*/
EAPI char * EAPI char *
eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len) eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len)
{ {