[hackers] [sbase] Make sort(1) utf-compliant and update README || FRIGN

From: <git_AT_suckless.org>
Date: Mon, 3 Aug 2015 20:15:00 +0200 (CEST)

commit e1534476570098ea257c84f77ebb96ad835a7c7b
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Mon Aug 3 17:35:01 2015 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Aug 3 19:14:52 2015 +0100

    Make sort(1) utf-compliant and update README
    
    Make it clear that <blank> characters just are spaces or tabs and
    not a special group which needs special treatment for wide characters.
    
    Also, and that was the only problem here, correctly calculate the
    offset given by the key definitions for the start- and end-characters
    using libutf-utility-functions.
    
    Mark the progress in the README and put parentheses around the missing
    flags which are insane to implement for no real gain.

diff --git a/README b/README
index 161e5b4..f0b2d44 100644
--- a/README
+++ b/README
_AT_@ -69,7 +69,7 @@ The following tools are implemented:
 =*|x sha256sum .
 =*|x sha512sum .
 =*|o sleep .
- sort -d, -f, -i
+# sort (-d, -f, -i)
 =*|o split .
 =*|x sponge .
 #*|o strings .
diff --git a/sort.c b/sort.c
index 1bd0fde..863220f 100644
--- a/sort.c
+++ b/sort.c
_AT_@ -6,6 +6,7 @@
 
 #include "queue.h"
 #include "text.h"
+#include "utf.h"
 #include "util.h"
 
 struct keydef {
_AT_@ -43,7 +44,7 @@ static size_t col1siz, col2siz;
 static char *
 skipblank(char *s)
 {
- while (isblank(*s))
+ while (*s == ' ' || *s == '\t')
                 s++;
         return s;
 }
_AT_@ -51,7 +52,7 @@ skipblank(char *s)
 static char *
 skipnonblank(char *s)
 {
- while (*s && *s != '\n' && !isblank(*s))
+ while (*s && *s != '\n' && *s != ' ' && *s != '\t')
                 s++;
         return s;
 }
_AT_@ -74,25 +75,35 @@ skipcolumn(char *s, char *eol, int next_col)
 static size_t
 columns(char *line, const struct keydef *kd, char **col, size_t *colsiz)
 {
+ Rune r;
         char *start, *end, *eol = strchr(line, '\n');
- size_t len;
+ size_t len, utflen, rlen;
         int i;
 
         for (i = 1, start = line; i < kd->start_column; i++)
                 start = skipcolumn(start, eol, 1);
         if (kd->flags & MOD_STARTB)
                 start = skipblank(start);
- start = MIN(eol, start + kd->start_char - 1);
+ for (utflen = 0; start < eol && utflen < kd->start_char - 1;) {
+ rlen = chartorune(&r, start);
+ start += rlen;
+ utflen++;
+ }
 
         if (kd->end_column) {
                 for (i = 1, end = line; i < kd->end_column; i++)
                         end = skipcolumn(end, eol, 1);
                 if (kd->flags & MOD_ENDB)
                         end = skipblank(end);
- if (kd->end_char)
- end = MIN(eol, end + kd->end_char);
- else
+ if (kd->end_char) {
+ for (utflen = 0; end < eol && utflen < kd->end_char;) {
+ rlen = chartorune(&r, end);
+ end += rlen;
+ utflen++;
+ }
+ } else {
                         end = skipcolumn(end, eol, 0);
+ }
         } else {
                 end = eol;
         }
Received on Mon Aug 03 2015 - 20:15:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 03 2015 - 20:24:10 CEST