summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authormongo <mongo@iomega>2016-08-26 14:02:06 -0300
committermongo <mongo@iomega>2016-08-26 14:02:06 -0300
commit2522fcb6fce3285a6e9284a3c019c0dfd0250def (patch)
tree06ecd5c7b7e120469603b17b6add14dd771c6031 /src/utils
parentb7a10636b09ac0b8877bca0b849d6cfc1d1ec592 (diff)
Added count_width_widestring function. it returns the number of wide chars needed to fill p column positions
Diffstat (limited to 'src/utils')
-rwxr-xr-xsrc/utils/string.c13
-rwxr-xr-xsrc/utils/string.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/string.c b/src/utils/string.c
index 16eefff..da04d3a 100755
--- a/src/utils/string.c
+++ b/src/utils/string.c
@@ -335,3 +335,16 @@ int sc_isprint(int d) {
return 1;
return 0;
}
+
+//return the number of wide chars of
+//wchar_t * s string, needed to fill p column positions.
+int count_width_widestring(const wchar_t * s, int p) {
+ int n;
+ int c_width = 0;
+
+ for (n=0; n<wcslen(s); n++) {
+ c_width += wcwidth( s[n] );
+ if (c_width > p) break;
+ }
+ return n;
+}
diff --git a/src/utils/string.h b/src/utils/string.h
index 10815ad..be54d9d 100755
--- a/src/utils/string.h
+++ b/src/utils/string.h
@@ -26,3 +26,4 @@ int count_word_occurrences(char * s, char * word, int overlap);
char * str_replace ( const char * string, const char * substr, const char * replacement);
void uppercase(char * sPtr);
int sc_isprint(int d);
+int count_width_widestring(const wchar_t * s, int p);