forked from enlightenment/efl
parent
5f64c38549
commit
270f765c91
|
@ -296,7 +296,17 @@ AC_HEADER_TIME
|
|||
|
||||
|
||||
### Checks for types
|
||||
AC_CHECK_HEADER([inttypes.h],
|
||||
[EINA_CONFIGURE_HAVE_INTTYPES_H="#define EINA_HAVE_INTTYPES_H"])
|
||||
AC_SUBST(EINA_CONFIGURE_HAVE_INTTYPES_H)
|
||||
|
||||
AC_CHECK_HEADER([stdint.h],
|
||||
[EINA_CONFIGURE_HAVE_STDINT_H="#define EINA_HAVE_STDINT_H"])
|
||||
AC_SUBST(EINA_CONFIGURE_HAVE_STDINT_H)
|
||||
|
||||
AC_CHECK_SIZEOF(wchar_t)
|
||||
EINA_SIZEOF_WCHAR_T=$ac_cv_sizeof_wchar_t
|
||||
AC_SUBST(EINA_SIZEOF_WCHAR_T)
|
||||
|
||||
### Checks for structures
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@ extern "C" {
|
|||
#include "eina_matrixsparse.h"
|
||||
#include "eina_str.h"
|
||||
#include "eina_strbuf.h"
|
||||
#include "eina_unicode.h"
|
||||
#include "eina_quadtree.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -46,6 +46,7 @@ eina_inline_tiler.x \
|
|||
eina_str.h \
|
||||
eina_inline_str.x \
|
||||
eina_strbuf.h \
|
||||
eina_unicode.h \
|
||||
eina_quadtree.h
|
||||
|
||||
installed_mainheaderdir = $(includedir)/eina-@VMAJ@
|
||||
|
|
|
@ -34,4 +34,19 @@
|
|||
#endif
|
||||
@EINA_CONFIGURE_SAFETY_CHECKS@
|
||||
|
||||
#ifdef EINA_HAVE_INTTYPES_H
|
||||
# undef EINA_HAVE_INTTYPES_H
|
||||
#endif
|
||||
@EINA_CONFIGURE_HAVE_INTTYPES_H@
|
||||
|
||||
#ifdef EINA_HAVE_STDINT_H
|
||||
# undef EINA_HAVE_STDINT_H
|
||||
#endif
|
||||
@EINA_CONFIGURE_HAVE_STDINT_H@
|
||||
|
||||
#ifdef EINA_SIZEOF_WCHAR_T
|
||||
# undef EINA_SIZEOF_WCHAR_T
|
||||
#endif
|
||||
#define EINA_SIZEOF_WCHAR_T @EINA_SIZEOF_WCHAR_T@
|
||||
|
||||
#endif /* EINA_CONFIG_H_ */
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
#ifndef EINA_UNICODE_H
|
||||
#define EINA_UNICODE_H
|
||||
|
||||
/**
|
||||
* @addtogroup Eina_Data_Types_Group Data Types
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @addtogroup Eina_Unicode_String Unicode String
|
||||
*
|
||||
* @brief These functions provide basic unicode string handling
|
||||
*
|
||||
* Eina_Unicode is a type that holds unicode codepoints.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "eina_config.h"
|
||||
|
||||
/**
|
||||
* @typedef Eina_Unicode
|
||||
* A type that holds Unicode codepoints.
|
||||
*/
|
||||
#if EINA_SIZEOF_WCHAR_T >= 4
|
||||
# include <wchar.h>
|
||||
typedef wchar_t Eina_Unicode;
|
||||
#elif defined(EINA_HAVE_INTTYPES_H)
|
||||
# include <inttypes.h>
|
||||
typedef uint32_t Eina_Unicode;
|
||||
#elif defined(EINA_HAVE_STDINT_H)
|
||||
# include <stdint.h>
|
||||
typedef uint32_t Eina_Unicode;
|
||||
#else
|
||||
/* Hope that int is big enough */
|
||||
typedef unsigned int Eina_Unicode;
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "eina_types.h"
|
||||
|
||||
extern const Eina_Unicode *EINA_UNICODE_EMPTY_STRING;
|
||||
|
||||
EAPI size_t
|
||||
eina_unicode_strlen(const Eina_Unicode *ustr) EINA_ARG_NONNULL(1);
|
||||
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strdup(const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
|
||||
|
||||
EAPI int
|
||||
eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2);
|
||||
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source);
|
||||
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2);
|
||||
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n);
|
||||
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_escape(const Eina_Unicode *str);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif
|
|
@ -39,6 +39,7 @@ eina_hamster.c \
|
|||
eina_safety_checks.c \
|
||||
eina_str.c \
|
||||
eina_strbuf.c \
|
||||
eina_unicode.c \
|
||||
eina_quadtree.c
|
||||
|
||||
if EINA_STATIC_BUILD_CHAINED_POOL
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/* EINA - EFL data type library
|
||||
* Copyright (C) 2010-2010 Tom Hacohen
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library;
|
||||
* if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include <Eina.h>
|
||||
#include "eina_unicode.h"
|
||||
|
||||
/* FIXME: check if sizeof(wchar_t) == sizeof(Eina_Unicode) if so,
|
||||
* probably better to use the standard functions */
|
||||
|
||||
const Eina_Unicode *EINA_UNICODE_EMPTY_STRING = {0};
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
for ( ; *a && *a == *b ; a++, b++)
|
||||
;
|
||||
if (*a == *b)
|
||||
return 0;
|
||||
else if (*a < *b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_Unicode *ret = dest;
|
||||
|
||||
while (*source)
|
||||
*dest++ = *source++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_Unicode *ret = dest;
|
||||
|
||||
for (n = 0 ; *source && n ; n--)
|
||||
*dest++ = *source++;
|
||||
for ( ; n ; n--)
|
||||
*dest++ = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Same as the standard strlen just with Eina_Unicode instead of char.
|
||||
*/
|
||||
EAPI size_t
|
||||
eina_unicode_strlen(const Eina_Unicode *ustr)
|
||||
{
|
||||
const Eina_Unicode *end;
|
||||
for (end = ustr ; *end ; end++)
|
||||
;
|
||||
return end - ustr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Same as the standard strdup just with Eina_Unicode instead of char.
|
||||
*/
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strdup(const Eina_Unicode *text)
|
||||
{
|
||||
Eina_Unicode *ustr;
|
||||
int len;
|
||||
|
||||
len = eina_unicode_strlen(text);
|
||||
ustr = (Eina_Unicode *) calloc(sizeof(Eina_Unicode), len + 1);
|
||||
memcpy(ustr, text, len * sizeof(Eina_Unicode));
|
||||
|
||||
return ustr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Same as the standard strdup just with Eina_Unicode instead of char.
|
||||
*/
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle)
|
||||
{
|
||||
const Eina_Unicode *i, *j;
|
||||
|
||||
for (i = haystack ; *i ; i++)
|
||||
{
|
||||
haystack = i; /* set this location as the base position */
|
||||
for (j = needle ; *j && *i && *j == *i ; j++, i++)
|
||||
;
|
||||
|
||||
if (!*j) /*if we got to the end of j this means we got a full match */
|
||||
{
|
||||
return (Eina_Unicode *) haystack; /* return the new base position */
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see eina_str_escape()
|
||||
*/
|
||||
EAPI Eina_Unicode *
|
||||
eina_unicode_escape(const Eina_Unicode *str)
|
||||
{
|
||||
Eina_Unicode *s2, *d;
|
||||
const Eina_Unicode *s;
|
||||
|
||||
s2 = malloc((eina_unicode_strlen(str) * 2) + 1);
|
||||
if (!s2) return NULL;
|
||||
for (s = str, d = s2; *s != 0; s++, d++)
|
||||
{
|
||||
if ((*s == ' ') || (*s == '\\') || (*s == '\''))
|
||||
{
|
||||
*d = '\\';
|
||||
d++;
|
||||
}
|
||||
*d = *s;
|
||||
}
|
||||
*d = 0;
|
||||
return s2;
|
||||
}
|
||||
|
Loading…
Reference in New Issue