You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/02 10:42:07 UTC
svn commit: r810416 - in /commons/sandbox/runtime/trunk/src/main/native:
include/acr.h include/acr_string.h shared/string.c
Author: mturk
Date: Wed Sep 2 08:42:07 2009
New Revision: 810416
URL: http://svn.apache.org/viewvc?rev=810416&view=rev
Log:
APR's apr_pstrcat with ansi and unicode versions
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr.h
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.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=810416&r1=810415&r2=810416&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Wed Sep 2 08:42:07 2009
@@ -300,11 +300,11 @@
#if defined(ACR_DECLARE_STATIC)
#define ACR_DECLARE(type) type __stdcall
-#define ACR_DECLARE_NONSTD(type) type
+#define ACR_DECLARE_NONSTD(type) type __cdecl
#define ACR_DECLARE_DATA
#elif defined(ACR_DECLARE_EXPORT)
#define ACR_DECLARE(type) __declspec(dllexport) type __stdcall
-#define ACR_DECLARE_NONSTD(type) __declspec(dllexport) type
+#define ACR_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
#define ACR_DECLARE_DATA __declspec(dllexport)
#else
/**
@@ -319,7 +319,7 @@
* ACR_DECLARE_NONSTD(), as they must use the C language calling convention.
*
*/
-#define ACR_DECLARE_NONSTD(type) __declspec(dllimport) type
+#define ACR_DECLARE_NONSTD(type) __declspec(dllimport) type __cdecl
/**
* The public ACR variables are declared with ACR_DECLARE_DATA.
* This assures the appropriate indirection is invoked at compile time.
@@ -341,7 +341,7 @@
* @endcode
*/
#define ACR_MODULE_DECLARE(type) type __stdcall
-#define ACR_MODULE_DECLARE_NONSTD(type) type
+#define ACR_MODULE_DECLARE_NONSTD(type) type __cdecl
#define ACR_MODULE_DECLARE_DATA
#else
/**
@@ -350,7 +350,7 @@
*/
#define ACR_MODULE_DECLARE_EXPORT
#define ACR_MODULE_DECLARE(type) __declspec(dllexport) type __stdcall
-#define ACR_MODULE_DECLARE_NONSTD(type) __declspec(dllexport) type
+#define ACR_MODULE_DECLARE_NONSTD(type) __declspec(dllexport) type __cdecl
#define ACR_MODULE_DECLARE_DATA __declspec(dllexport)
#endif
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=810416&r1=810415&r2=810416&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 Wed Sep 2 08:42:07 2009
@@ -197,6 +197,34 @@
wchar_t *src, const wchar_t *str);
/**
+ * Concatenate multiple strings.
+ * @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.
+ * @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_NONSTD(char *) ACR_StrvcatA(JNIEnv *env, const char *file, int line,
+ char *src, ...);
+
+/**
+ * Unicode version of multiple string concatenation.
+ * @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.
+ * @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_NONSTD(wchar_t *) ACR_StrvcatW(JNIEnv *env, const char *file, int line,
+ wchar_t *src, ...);
+
+/**
* 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=810416&r1=810415&r2=810416&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Wed Sep 2 08:42:07 2009
@@ -652,6 +652,116 @@
return d;
}
+#define MAX_SAVED_LENGTHS 32
+
+ACR_DECLARE_NONSTD(char *) ACR_StrvcatA(JNIEnv *_E, const char *file, int line,
+ char *p, ...)
+{
+ char *cp, *argp, *res;
+ size_t saved_lengths[MAX_SAVED_LENGTHS];
+ int nargs = 0;
+
+ /* Pass one --- find length of required string */
+ size_t len = 0;
+ va_list adummy;
+
+ if (p) {
+ len = strlen(p);
+ }
+ va_start(adummy, p);
+ while ((cp = va_arg(adummy, char *)) != NULL) {
+ size_t cplen = strlen(cp);
+ if (nargs < MAX_SAVED_LENGTHS) {
+ saved_lengths[nargs++] = cplen;
+ }
+ len += cplen;
+ }
+ va_end(adummy);
+
+ /* Allocate the required string */
+
+ res = (char *)ACR_Malloc(_E, file, line, len + 1);
+ cp = res;
+ if (p) {
+ memcpy(cp, p, strlen(p));
+ cp += strlen(p);
+ free(p);
+ }
+ /* Pass two --- copy the argument strings into the result space */
+ nargs = 0;
+ va_start(adummy, p);
+ while ((argp = va_arg(adummy, char *)) != NULL) {
+ if (nargs < MAX_SAVED_LENGTHS) {
+ len = saved_lengths[nargs++];
+ }
+ else {
+ len = strlen(argp);
+ }
+
+ memcpy(cp, argp, len);
+ cp += len;
+ }
+ va_end(adummy);
+
+ /* Return the result string */
+ *cp = '\0';
+ return res;
+}
+
+ACR_DECLARE_NONSTD(wchar_t *) ACR_StrvcatW(JNIEnv *_E, const char *file, int line,
+ wchar_t *p, ...)
+{
+ wchar_t *cp, *argp, *res;
+ size_t saved_lengths[MAX_SAVED_LENGTHS];
+ int nargs = 0;
+
+ /* Pass one --- find length of required string */
+ size_t len = 0;
+ va_list adummy;
+
+ if (p) {
+ len = wcslen(p);
+ }
+ va_start(adummy, p);
+ while ((cp = va_arg(adummy, wchar_t *)) != NULL) {
+ size_t cplen = wcslen(cp);
+ if (nargs < MAX_SAVED_LENGTHS) {
+ saved_lengths[nargs++] = cplen;
+ }
+ len += cplen;
+ }
+ va_end(adummy);
+
+ /* Allocate the required string */
+
+ res = (wchar_t *)ACR_Malloc(_E, file, line, (len + 1) * sizeof(wchar_t));
+ cp = res;
+ if (p) {
+ memcpy(cp, p, wcslen(p) * sizeof(wchar_t));
+ cp += wcslen(p);
+ free(p);
+ }
+ /* Pass two --- copy the argument strings into the result space */
+ nargs = 0;
+ va_start(adummy, p);
+ while ((argp = va_arg(adummy, wchar_t *)) != NULL) {
+ if (nargs < MAX_SAVED_LENGTHS) {
+ len = saved_lengths[nargs++];
+ }
+ else {
+ len = wcslen(argp);
+ }
+
+ memcpy(cp, argp, len * sizeof(wchar_t));
+ cp += len;
+ }
+ va_end(adummy);
+
+ /* Return the result string */
+ *cp = L'\0';
+ return res;
+}
+
ACR_DECLARE(char *) ACR_Itoa(acr_int_t n)
{
const int BUFFER_SIZE = 16;