commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r806842 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_string.h shared/string.c
Date Sat, 22 Aug 2009 11:28:49 GMT
Author: mturk
Date: Sat Aug 22 11:28:49 2009
New Revision: 806842

URL: http://svn.apache.org/viewvc?rev=806842&view=rev
Log:
Add srtcat replacement function

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=806842&r1=806841&r2=806842&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Sat Aug 22 11:28:49
2009
@@ -167,6 +167,36 @@
                                    const wchar_t *s);
 
 /**
+ * Concatenate string.
+ * @param env Current JNI environment.
+ * @param file Source file where the function was called
+ * @param line Source file line where the function was called
+ * @param src Existing string to use.
+ * @param str String to concatenate.
+ * @return Pointer to concatenated string.
+ * @note If src is not NULL it is free'd after concatenation and a new
+ *       string is returned. Use free when no longer needed.
+ *       In case src is NULL the function behaves like strdup.
+ */
+ACR_DECLARE(char *) ACR_StrcatA(JNIEnv *env, const char *file, int line,
+                                char *src, const char *str);
+
+/**
+ * Unicode version of concatenate string.
+ * @param env Current JNI environment.
+ * @param file Source file where the function was called
+ * @param line Source file line where the function was called
+ * @param src Existing string to use.
+ * @param str String to concatenate.
+ * @return Pointer to concatenated string.
+ * @note If src is not NULL it is free'd after concatenation and a new
+ *       string is returned. Use free when no longer needed.
+ *       In case src is NULL the function behaves like wcsdup.
+ */
+ACR_DECLARE(wchar_t *) ACR_StrcatW(JNIEnv *env, const char *file, int line,
+                                   wchar_t *src, const wchar_t *str);
+
+/**
  * Apache's "replacement" for the strtok_r() function that uses
  * a single char instead set of delimiters.
  * @param str string to tokenize.

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=806842&r1=806841&r2=806842&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Sat Aug 22 11:28:49 2009
@@ -604,6 +604,54 @@
     return d;
 }
 
+ACR_DECLARE(char *) ACR_StrcatA(JNIEnv *_E, const char *file, int line,
+                                char *p, const char *s)
+{
+    char *d = NULL;
+    if (s && *s) {
+        size_t srcs = 0;
+        size_t size = strlen(s);
+        if (p)
+            srcs = strlen(p);
+        d = ACR_Malloc(_E, file, line, size + srcs + 1);
+        if (d) {
+            if (p) {
+                memcpy(d, p, srcs);
+                free(p);
+            }
+            memcpy(d + srcs, s, size);
+            d[size + srcs] = '\0';
+        }
+    }
+    else
+        d = p;
+    return d;
+}
+
+ACR_DECLARE(wchar_t *) ACR_StrcatW(JNIEnv *_E, const char *file, int line,
+                                   wchar_t *p, const wchar_t *s)
+{
+    wchar_t *d = NULL;
+    if (s && *s) {
+        size_t srcs = 0;
+        size_t size = wcslen(s);
+        if (p)
+            srcs = wcslen(p);
+        d = ACR_Malloc(_E, file, line, (size + srcs + 1) * sizeof(wchar_t));
+        if (d) {
+            if (p) {
+                memcpy(d, p, srcs * sizeof(wchar_t));
+                free(p);
+            }
+            memcpy(d + srcs, s, size * sizeof(wchar_t));
+            d[size + srcs] = L'\0';
+        }
+    }
+    else
+        d = p;
+    return d;
+}
+
 ACR_DECLARE(char *) ACR_Itoa(acr_int_t n)
 {
     const int BUFFER_SIZE = 16;



Mime
View raw message