svn commit: r1934431 - subversion/trunk/subversion/svnbrowse

[email protected]
Newsgroups gmane.comp.version-control.subversion.svn
Message-ID <177927634882.1202516.2443502144043178941@svn03-he-fi>
Author: rinrab
Date: Wed May 20 11:25:48 2026
New Revision: 1934431

Log:
svnbrowse: Use UTF-8 functions for alignement.

* subversion/svnbrowse/svnbrowse.c
  (#includes): Add svn_utf_private.h.
  (leftpad, rightpad): Remove those functions.
  (view_draw_item, view_draw_header, view_draw_footer): Use
   svn_utf__cstring_utf8_align_right() and svn_utf__cstring_utf8_align_left()
   instead of leftpad() and rightpad() respectfully.

Modified:
   subversion/trunk/subversion/svnbrowse/svnbrowse.c

Modified: subversion/trunk/subversion/svnbrowse/svnbrowse.c
==============================================================================
--- subversion/trunk/subversion/svnbrowse/svnbrowse.c	Wed May 20 09:21:15 2026	(r1934430)
+++ subversion/trunk/subversion/svnbrowse/svnbrowse.c	Wed May 20 11:25:48 2026	(r1934431)
@@ -24,6 +24,7 @@
 
 #include <apr.h>
 
+#include "private/svn_utf_private.h"
 #include "svn_cmdline.h"
 #include "svn_opt.h"
 #include "svn_ra.h"
@@ -344,57 +345,6 @@ view_on_event(svn_browse__view_t *view,
   return SVN_NO_ERROR;
 }
 
-static char *
-rightpad(const char *cstr, int padding, apr_pool_t *result_pool)
-{
-  int len = strlen(cstr);
-  char *result;
-
-  if (padding < 0)
-    padding = 0;
-
-  result = apr_palloc(result_pool, padding + 1);
-
-  if (len < padding)
-    {
-      memcpy(result, cstr, len);
-      memset(result + len, ' ', padding - len);
-    }
-  else
-    {
-      memcpy(result, cstr, len);
-    }
-
-  result[padding] = '\0';
-  return result;
-}
-
-static char *
-leftpad(const char *cstr, int padding, apr_pool_t *result_pool)
-{
-  int len = strlen(cstr);
-  char *result;
-
-  if (padding < 0)
-    padding = 0;
-
-  result = apr_palloc(result_pool, padding + 1);
-
-  if (len < padding)
-    {
-      int spaces = padding - len;
-      memset(result, ' ', spaces);
-      memcpy(result + spaces, cstr, len);
-    }
-  else
-    {
-      memcpy(result, cstr, len);
-    }
-
-  result[padding] = '\0';
-  return result;
-}
-
 static const char *
 format_node_size(const svn_browse__item_t *item, apr_pool_t *pool)
 {
@@ -442,17 +392,21 @@ view_draw_item(const svn_browse__style_t
   /* 12 + 12 + (20 + 1) + 2 = 47 */
 
   waddch(win, ' ');
-  waddstr(win, rightpad(format_node_name(item, scratch_pool),
-                        getmaxx(win) - 47, scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_left(
+                   format_node_name(item, scratch_pool), getmaxx(win) - 47,
+                   scratch_pool));
 
   wattrset(win, get_item_style(style, svn_node_file, selected));
-  waddstr(win,
-          leftpad(format_node_size(item, scratch_pool), 12, scratch_pool));
-  waddstr(win, leftpad(apr_psprintf(scratch_pool, "r%ld",
-                                    item->dirent->created_rev),
-                       12, scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_right(
+                   format_node_size(item, scratch_pool),
+                   12, scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_right(
+                   apr_psprintf(scratch_pool, "r%ld",
+                                item->dirent->created_rev),
+                   12, scratch_pool));
   waddch(win, ' ');
-  waddstr(win, rightpad(item->dirent->last_author, 20, scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_left(
+                   item->dirent->last_author, 20, scratch_pool));
   waddch(win, ' ');
 }
 
@@ -483,9 +437,10 @@ view_draw_header(svn_browse__view_t *vie
   wmove(win, 0, 0);
   wattrset(win, view->style->header);
   waddstr(win, prefix);
-  waddstr(win, rightpad(apr_psprintf(scratch_pool, "URL: %s", abspath),
-                        getmaxx(win) - strlen(prefix) - strlen(suffix),
-                        scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_left(
+                   apr_psprintf(scratch_pool, "URL: %s", abspath),
+                   getmaxx(win) - strlen(prefix) - strlen(suffix),
+                   scratch_pool));
   waddstr(win, suffix);
 }
 
@@ -528,20 +483,23 @@ view_draw_footer(svn_browse__view_t *vie
   wmove(win, 0, 0);
   wattrset(win, view->style->footer);
   waddstr(win, "  ");
-  waddstr(win, rightpad(apr_psprintf(scratch_pool, "Ready"),
-                        getmaxx(win) - 4 - strlen(brand) - 16,
-                        scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_left(
+                  apr_psprintf(scratch_pool, "Ready"),
+                  getmaxx(win) - 4 - strlen(brand) - 16,
+                  scratch_pool));
   waddstr(win, brand);
 
-  waddstr(win, leftpad(apr_psprintf(scratch_pool, "%d/%d",
-                                    state->selection + 1,
-                                    view_get_list_height(state)),
-                       8, scratch_pool));
-  waddstr(win, leftpad(format_percentage_scroll(state->scroller_offset,
-                                                view_get_list_height(state),
-                                                getmaxy(view->list),
-                                                scratch_pool),
-                       8, scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_right(
+                  apr_psprintf(scratch_pool, "%d/%d",
+                               state->selection + 1,
+                               view_get_list_height(state)),
+                  8, scratch_pool));
+  waddstr(win, svn_utf__cstring_utf8_align_right(
+                  format_percentage_scroll(state->scroller_offset,
+                                           view_get_list_height(state),
+                                           getmaxy(view->list),
+                                           scratch_pool),
+                  8, scratch_pool));
   waddstr(win, "  ");
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.