summaryrefslogtreecommitdiffstats
path: root/src/rccstring.c
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-18 15:22:28 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2005-07-18 15:22:28 +0000
commit537c4b33fdf6e143243d5a0d286eeb247362e806 (patch)
treed8a94cfaa4a71ffc826b7d8176c54445369539f3 /src/rccstring.c
parent4032f92867e5570f130e4175b3b4fb61240f9752 (diff)
downloadlibrcc-537c4b33fdf6e143243d5a0d286eeb247362e806.tar.gz
librcc-537c4b33fdf6e143243d5a0d286eeb247362e806.tar.bz2
librcc-537c4b33fdf6e143243d5a0d286eeb247362e806.tar.xz
librcc-537c4b33fdf6e143243d5a0d286eeb247362e806.zip
API Improvements
- Removed 'rlen' return parameters there not necessary for multibyte encodings - Two versions of recode functions: rccRecode -> rccRecode, rccSizedRecode - Class Types: CONST, SKIP_SAVELOAD - New recode functions: rccToCharset, rccFromCharset - More new recode functions: rccRecodeToCharset, rccRecodeFromCharset, rccRecodeCharsets - New function: rccGetCompiledConfiguration - All warnings are fixed - Perform "File Name" search only if there are non ISO8859-1 chars in the name. - Do not copy invalid characters, - skip them. - Fixed error in rccRecode with 'Recoding Cache' switched On. - Strip leading and trailing spaces in rccDB4 get/set
Diffstat (limited to 'src/rccstring.c')
-rw-r--r--src/rccstring.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/rccstring.c b/src/rccstring.c
index bd5ef15..d6c6805 100644
--- a/src/rccstring.c
+++ b/src/rccstring.c
@@ -1,19 +1,23 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include "../config.h"
+
#include "internal.h"
#include "rccstring.h"
-rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t len, size_t *rlen) {
+rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t len) {
char *res;
rcc_string_header *header;
-
- len = STRNLEN(buf, len);
+
+ if (!buf) return NULL;
+ if (!len) len = strlen(buf);
res = (char*)malloc(len+sizeof(rcc_string_header)+1);
if (!res) return NULL;
- strncpy(res + sizeof(rcc_string_header), buf, len);
+ memcpy(res + sizeof(rcc_string_header), buf, len);
res[sizeof(rcc_string_header) + len] = 0;
memset(res, 0xFF, sizeof(rcc_string_header));
@@ -21,7 +25,6 @@ rcc_string rccCreateString(rcc_language_id language_id, const char *buf, size_t
header->magic = RCC_STRING_MAGIC;
header->language_id = language_id;
- if (rlen) *rlen = len + sizeof(rcc_string_header);
return (rcc_string)res;
}
@@ -78,7 +81,7 @@ size_t rccStringSizedCheck(const char *str, size_t len) {
if (!str) return 0;
- newlen = STRNLEN(str, len);
+ newlen = len?len:strlen(str);
if (newlen>sizeof(rcc_string_header)) {
if ((len==newlen)&&(!str[newlen-2])) return 0;
newlen-=sizeof(rcc_string_header);
@@ -88,16 +91,16 @@ size_t rccStringSizedCheck(const char *str, size_t len) {
}
-rcc_language_id rccStringGetLanguage(const rcc_string str) {
+rcc_language_id rccStringGetLanguage(rcc_const_string str) {
if (!str) return (rcc_language_id)-1;
return ((rcc_string_header*)str)->language_id;
}
-const char *rccStringGetString(const rcc_string str) {
+const char *rccStringGetString(rcc_const_string str) {
return (const char *)str + sizeof(rcc_string_header);
}
-char *rccStringExtractString(const rcc_string str) {
+char *rccStringExtractString(rcc_const_string str) {
size_t len;
char *res;
@@ -107,7 +110,7 @@ char *rccStringExtractString(const rcc_string str) {
res = (char*)malloc(len+1);
if (!res) return NULL;
- strncpy(res, rccStringGetString(str), len);
+ memcpy(res, rccStringGetString(str), len);
res[len] = 0;
return res;
@@ -119,12 +122,11 @@ const char *rccGetString(const char *str) {
return str;
}
-const char *rccSizedGetString(const char *str, size_t len, size_t *rlen) {
+const char *rccSizedGetString(const char *str, size_t len) {
size_t newlen;
newlen = rccStringSizedCheck(str, len);
if (newlen) {
- if (rlen) *rlen = newlen;
return rccStringGetString((const rcc_string)str);
}
@@ -148,3 +150,19 @@ int rccStringNCaseCmp(const char *str1, const char *str2, size_t n) {
return strncasecmp(rccGetString(str1), rccGetString(str2), n);
}
+#ifndef HAVE_STRNLEN
+int rccStrnlen(const char *str, size_t size) {
+ unsigned int i;
+ for (i=0;((i<size)&&(str[i]));i++);
+ return i;
+}
+#endif /* HAVE_STRNLEN */
+
+
+int rccIsASCII(const char *str) {
+ unsigned int i;
+
+ for (i=0;str[i];i++)
+ if ((unsigned char)str[i]>0x7F) return 0;
+ return 1;
+}