You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/10/23 10:20:40 UTC

svn commit: r1534953 - in /subversion/trunk/subversion: bindings/javahl/native/JNIUtil.cpp include/private/svn_utf_private.h libsvn_subr/cmdline.c libsvn_subr/config_win.c libsvn_subr/nls.c libsvn_subr/utf.c

Author: brane
Date: Wed Oct 23 08:20:40 2013
New Revision: 1534953

URL: http://svn.apache.org/r1534953
Log:
Add an optional prefix parameter to the Windows-specific UTF-8 <-> UTF-16
conversion functions.

* subversion/include/private/svn_utf_private.h
  (svn_utf__win32_utf8_to_utf16, svn_utf__win32_utf16_to_utf8):
   Added prefix argument and updated docstrings.
* subversion/libsvn_subr/utf.c
  (svn_utf__win32_utf8_to_utf16, svn_utf__win32_utf16_to_utf8):
   Implemented prefix handling.
* subversion/bindings/javahl/native/JNIUtil.cpp,
  subversion/libsvn_subr/cmdline.c,
  subversion/libsvn_subr/config_win.c,
  subversion/libsvn_subr/nls.c: Updated all callers.

Modified:
    subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
    subversion/trunk/subversion/include/private/svn_utf_private.h
    subversion/trunk/subversion/libsvn_subr/cmdline.c
    subversion/trunk/subversion/libsvn_subr/config_win.c
    subversion/trunk/subversion/libsvn_subr/nls.c
    subversion/trunk/subversion/libsvn_subr/utf.c

Modified: subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1534953&r1=1534952&r2=1534953&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/JNIUtil.cpp Wed Oct 23 08:20:40 2013
@@ -313,7 +313,7 @@ bool JNIUtil::JNIGlobalInit(JNIEnv *env)
     HINSTANCE moduleHandle = GetModuleHandle("libsvnjavahl-1");
     GetModuleFileNameW(moduleHandle, ucs2_path,
                        sizeof(ucs2_path) / sizeof(ucs2_path[0]));
-    err = svn_utf__win32_utf16_to_utf8(&utf8_path, ucs2_path, pool);
+    err = svn_utf__win32_utf16_to_utf8(&utf8_path, ucs2_path, NULL, pool);
     if (err)
       {
         if (stderr)

Modified: subversion/trunk/subversion/include/private/svn_utf_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_utf_private.h?rev=1534953&r1=1534952&r2=1534953&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_utf_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_utf_private.h Wed Oct 23 08:20:40 2013
@@ -95,16 +95,22 @@ svn_utf__cstring_from_utf8_fuzzy(const c
 
 
 #if defined(WIN32)
-/* On Windows: Convert the UTF-8 string SRC to UTF-16. */
+/* On Windows: Convert the UTF-8 string SRC to UTF-16.
+   If PREFIX is not NULL, prepend it to the converted result.
+   The result, if not empty, will be allocated in RESULT_POOL. */
 svn_error_t *
 svn_utf__win32_utf8_to_utf16(const WCHAR **result,
                              const char *src,
+                             const WCHAR *prefix,
                              apr_pool_t *result_pool);
 
-/* On Windows: Convert the UTF-16 string SRC to UTF-8. */
+/* On Windows: Convert the UTF-16 string SRC to UTF-8.
+   If PREFIX is not NULL, prepend it to the converted result.
+   The result, if not empty, will be allocated in RESULT_POOL. */
 svn_error_t *
 svn_utf__win32_utf16_to_utf8(const char **result,
                              const WCHAR *src,
+                             cosnt char *prefix,
                              apr_pool_t *result_pool);
 #endif /* WIN32*/
 

Modified: subversion/trunk/subversion/libsvn_subr/cmdline.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cmdline.c?rev=1534953&r1=1534952&r2=1534953&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cmdline.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cmdline.c Wed Oct 23 08:20:40 2013
@@ -406,7 +406,7 @@ svn_cmdline_fputs(const char *string, FI
 
       SVN_ERR(svn_cmdline_fflush(stream)); /* Flush existing output */
 
-      SVN_ERR(svn_utf__win32_utf8_to_utf16(&result, string, pool));
+      SVN_ERR(svn_utf__win32_utf8_to_utf16(&result, string, NULL, pool));
 
       if (_cputws(result))
         {

Modified: subversion/trunk/subversion/libsvn_subr/config_win.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/config_win.c?rev=1534953&r1=1534952&r2=1534953&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/config_win.c (original)
+++ subversion/trunk/subversion/libsvn_subr/config_win.c Wed Oct 23 08:20:40 2013
@@ -66,7 +66,7 @@ svn_config__win_config_path(const char *
                            : "Can't determine the user's config path"));
 
   return svn_error_trace(svn_utf__win32_utf16_to_utf8(folder, folder_ucs2,
-                                                      result_pool));
+                                                      NULL, result_pool));
 }
 
 

Modified: subversion/trunk/subversion/libsvn_subr/nls.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/nls.c?rev=1534953&r1=1534952&r2=1534953&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/nls.c (original)
+++ subversion/trunk/subversion/libsvn_subr/nls.c Wed Oct 23 08:20:40 2013
@@ -71,7 +71,7 @@ svn_nls_init(void)
 
       if (! err)
         err = svn_utf__win32_utf16_to_utf8(&utf8_path, ucs2_path,
-                                           scratch_pool);
+                                           NULL, scratch_pool);
 
       if (! err)
         {

Modified: subversion/trunk/subversion/libsvn_subr/utf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/utf.c?rev=1534953&r1=1534952&r2=1534953&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/utf.c (original)
+++ subversion/trunk/subversion/libsvn_subr/utf.c Wed Oct 23 08:20:40 2013
@@ -1028,13 +1028,15 @@ svn_utf_cstring_from_utf8_string(const c
 svn_error_t *
 svn_utf__win32_utf8_to_utf16(const WCHAR **result,
                              const char *src,
+                             const WCHAR *prefix,
                              apr_pool_t *result_pool)
 {
   const int utf8_count = strlen(src);
+  const int prefix_len = (prefix ? lstrlenW(prefix) : 0);
   WCHAR *wide_str;
   int wide_count;
 
-  if (!utf8_count)
+  if (0 == prefix_len + utf8_count)
     {
       *result = L"";
       return SVN_NO_ERROR;
@@ -1045,13 +1047,16 @@ svn_utf__win32_utf8_to_utf16(const WCHAR
     return svn_error_wrap_apr(apr_get_os_error(),
                               _("Conversion to UTF-16 failed"));
 
-  wide_str = apr_palloc(result_pool, (wide_count + 1) * sizeof(*wide_str));
+  wide_str = apr_palloc(result_pool,
+                        (prefix_len + wide_count + 1) * sizeof(*wide_str));
+  if (prefix_len)
+    memcpy(wide_str, prefix, prefix_len * sizeof(*wide_str));
   if (0 == MultiByteToWideChar(CP_UTF8, 0, src, utf8_count,
-                               wide_str, wide_count))
+                               wide_str + prefix_len, wide_count))
     return svn_error_wrap_apr(apr_get_os_error(),
                               _("Conversion to UTF-16 failed"));
 
-  wide_str[wide_count] = 0;
+  wide_str[prefix_len + wide_count] = 0;
   *result = wide_str;
 
   return SVN_NO_ERROR;
@@ -1060,13 +1065,15 @@ svn_utf__win32_utf8_to_utf16(const WCHAR
 svn_error_t *
 svn_utf__win32_utf16_to_utf8(const char **result,
                              const WCHAR *src,
+                             const char *prefix,
                              apr_pool_t *result_pool)
 {
   const int wide_count = lstrlenW(src);
+  const int prefix_len = (prefix ? strlen(prefix) : 0);
   char *utf8_str;
   int utf8_count;
 
-  if (!wide_count)
+  if (0 == prefix_len + wide_count)
     {
       *result = "";
       return SVN_NO_ERROR;
@@ -1078,13 +1085,17 @@ svn_utf__win32_utf16_to_utf8(const char 
     return svn_error_wrap_apr(apr_get_os_error(),
                               _("Conversion from UTF-16 failed"));
 
-  utf8_str = apr_palloc(result_pool, (utf8_count + 1) * sizeof(*utf8_str));
+  utf8_str = apr_palloc(result_pool,
+                        (prefix_len + utf8_count + 1) * sizeof(*utf8_str));
+  if (prefix_len)
+    memcpy(utf8_str, prefix, prefix_len * sizeof(*utf8_str));
   if (0 == WideCharToMultiByte(CP_UTF8, 0, src, wide_count,
-                               utf8_str, utf8_count, NULL, FALSE))
+                               utf8_str + prefix_len, utf8_count,
+                               NULL, FALSE))
     return svn_error_wrap_apr(apr_get_os_error(),
                               _("Conversion from UTF-16 failed"));
 
-  utf8_str[utf8_count] = 0;
+  utf8_str[prefix_len + utf8_count] = 0;
   *result = utf8_str;
 
   return SVN_NO_ERROR;