summaryrefslogtreecommitdiffstats
path: root/src/rccstring.c
diff options
context:
space:
mode:
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;
+}