summaryrefslogtreecommitdiff
path: root/src/utilfuns/utilstr.cpp
diff options
context:
space:
mode:
authorRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
committerRoberto C. Sanchez <roberto@connexer.com>2014-03-29 10:53:49 -0400
commit8c8aa6b07e595cfac56838b5964ab3e96051f1b2 (patch)
treeda38e2c1979148dbd3b0c7b87f930746f5ba7f44 /src/utilfuns/utilstr.cpp
parent8d3fc864d094eeadc721f8e93436b37a5fab173e (diff)
Imported Upstream version 1.5.7
Diffstat (limited to 'src/utilfuns/utilstr.cpp')
-rw-r--r--src/utilfuns/utilstr.cpp82
1 files changed, 67 insertions, 15 deletions
diff --git a/src/utilfuns/utilstr.cpp b/src/utilfuns/utilstr.cpp
index 366c54f..79904c6 100644
--- a/src/utilfuns/utilstr.cpp
+++ b/src/utilfuns/utilstr.cpp
@@ -1,6 +1,19 @@
-#include <string.h>
#include <utilstr.h>
#include <ctype.h>
+#include <string.h>
+
+#ifdef _ICU_
+#include <unicode/utypes.h>
+#include <unicode/ucnv.h>
+#include <unicode/ustring.h>
+#include <unicode/uchar.h>
+
+#include <unicode/unistr.h>
+#include <unicode/translit.h>
+
+#endif
+
+SWORD_NAMESPACE_START
/******************************************************************************
* stdstr - Sets/gets a string
@@ -12,12 +25,12 @@
* RET: *ipstr
*/
-char *stdstr(char **ipstr, const char *istr) {
+char *stdstr(char **ipstr, const char *istr, unsigned int memPadFactor) {
if (istr) {
if (*ipstr)
delete [] *ipstr;
int len = strlen(istr) + 1;
- *ipstr = new char [ len ];
+ *ipstr = new char [ len * memPadFactor ];
memcpy(*ipstr, istr, len);
}
return *ipstr;
@@ -41,8 +54,8 @@ char *strstrip(char *istr) {
return istr;
rtmp = istr + (len - 1);
- while (*rtmp == ' ') *(rtmp--) = 0;
- while (*tmp == ' ') tmp++;
+ while ((rtmp > istr)&&((*rtmp == ' ')||(*rtmp == '\t')||(*rtmp == 10)||(*rtmp == 13))) *(rtmp--) = 0;
+ while ((*tmp == ' ')||(*tmp == '\t')||(*tmp == 10)||(*tmp == 13)) tmp++;
memmove(istr, tmp, (rtmp - tmp) + 1);
istr[(rtmp - tmp) + 1] = 0;
@@ -95,18 +108,17 @@ const char *stristr(const char *s1, const char *s2) {
*/
const char strnicmp(const char *s1, const char *s2, int len) {
-
- int tLen = strlen(s2);
- int cLen = strlen(s1);
- char diff;
- int i;
- for (i = 0; ((i < len) && (i < tLen) && (i < cLen)); i++) {
- if ((diff = SW_toupper(*s1) - SW_toupper(*s2)))
- return diff;
+ int tLen = strlen(s2);
+ int cLen = strlen(s1);
+ char diff;
+ int i;
+ for (i = 0; ((i < len) && (i < tLen) && (i < cLen)); i++) {
+ if ((diff = SW_toupper(*s1) - SW_toupper(*s2)))
+ return diff;
s1++;
s2++;
- }
- return (i < len) ? cLen - tLen : 0;
+ }
+ return (i < len) ? cLen - tLen : 0;
}
/******************************************************************************
@@ -145,8 +157,48 @@ unsigned int strlenw(const char *s1) {
char *toupperstr(char *buf) {
char *ret = buf;
+
while (*buf)
*buf = SW_toupper(*buf++);
return ret;
}
+
+
+/******************************************************************************
+ * toupperstr - converts a string to uppercase string
+ *
+ * ENT: target - string to convert
+ *
+ * RET: target
+ */
+
+char *toupperstr_utf8(char *buf, unsigned int max) {
+ char *ret = buf;
+
+#ifndef _ICU_
+ // try to decide if it's worth trying to toupper. Do we have more
+ // characters that are probably lower latin than not?
+ long performOp = 0;
+ for (const char *ch = buf; *ch; ch++)
+ performOp += (*ch > 0) ? 1 : -1;
+
+ if (performOp) {
+ while (*buf)
+ *buf = SW_toupper(*buf++);
+ }
+#else
+ if (!max)
+ max = strlen(ret);
+ UErrorCode err = U_ZERO_ERROR;
+ UConverter *conv = ucnv_open("UTF-8", &err);
+ UnicodeString str(buf, -1, conv, err);
+ UnicodeString ustr = str.toUpper();
+ ustr.extract(ret, max, conv, err);
+ ucnv_close(conv);
+#endif
+
+ return ret;
+}
+
+SWORD_NAMESPACE_END