Ignore:
Timestamp:
2019-02-05T18:26:05Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
1d2f85e
Parents:
d066259
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-05 16:16:55)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-05 18:26:05)
Message:

Use clearer naming for string length functions

This and the following commit change the names of functions, as well as
their documentation, to use unambiguous terms "bytes" and "code points"
instead of ambiguous terms "size", "length", and "characters".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/kconsole.c

    rd066259 r08e103d4  
    167167{
    168168        link_t **startpos = (link_t **) ctx;
    169         size_t namelen = str_length(name);
     169        size_t namelen = str_code_points(name);
    170170
    171171        spinlock_lock(&cmd_lock);
     
    178178
    179179                const char *curname = hlp->name;
    180                 if (str_length(curname) < namelen)
     180                if (str_code_points(curname) < namelen)
    181181                        continue;
    182182
     
    187187
    188188                        spinlock_unlock(&cmd_lock);
    189                         return (curname + str_lsize(curname, namelen));
     189                        return (curname + str_lbytes(curname, namelen));
    190190                }
    191191        }
     
    233233
    234234        while ((hint = hints_enum(name, NULL, &pos))) {
    235                 if ((found == 0) || (str_length(hint) > str_length(output)))
     235                if ((found == 0) || (str_code_points(hint) > str_code_points(output)))
    236236                        str_cpy(output, MAX_CMDLINE, hint);
    237237
     
    249249        }
    250250
    251         if ((found > 1) && (str_length(output) != 0)) {
     251        if ((found > 1) && (str_code_points(output) != 0)) {
    252252                printf("\n");
    253253                pos = NULL;
     
    358358                                putwchar('\b');
    359359                                printf("%ls ", current + position);
    360                                 print_cc('\b', wstr_length(current) - position + 1);
     360                                print_cc('\b', wstr_code_points(current) - position + 1);
    361361                                continue;
    362362                        }
     
    440440                                printf("%s> ", prompt);
    441441                                printf("%ls", current);
    442                                 position += str_length(tmp);
    443                                 print_cc('\b', wstr_length(current) - position);
     442                                position += str_code_points(tmp);
     443                                print_cc('\b', wstr_code_points(current) - position);
    444444                                continue;
    445445                        }
     
    448448
    449449                        printf("%ls", current + position);
    450                         position += str_length(tmp);
    451                         print_cc('\b', wstr_length(current) - position);
    452 
    453                         if (position == wstr_length(current)) {
     450                        position += str_code_points(tmp);
     451                        print_cc('\b', wstr_code_points(current) - position);
     452
     453                        if (position == wstr_code_points(current)) {
    454454                                /* Insert a space after the last completed argument */
    455455                                if (wstr_linsert(current, ' ', position, MAX_CMDLINE)) {
     
    472472                if (ch == U_RIGHT_ARROW) {
    473473                        /* Right */
    474                         if (position < wstr_length(current)) {
     474                        if (position < wstr_code_points(current)) {
    475475                                putwchar(current[position]);
    476476                                position++;
     
    482482                        /* Up, down */
    483483                        print_cc('\b', position);
    484                         print_cc(' ', wstr_length(current));
    485                         print_cc('\b', wstr_length(current));
     484                        print_cc(' ', wstr_code_points(current));
     485                        print_cc('\b', wstr_code_points(current));
    486486
    487487                        if (ch == U_UP_ARROW) {
     
    498498                        current = history[history_pos];
    499499                        printf("%ls", current);
    500                         position = wstr_length(current);
     500                        position = wstr_code_points(current);
    501501                        continue;
    502502                }
     
    512512                        /* End */
    513513                        printf("%ls", current + position);
    514                         position = wstr_length(current);
     514                        position = wstr_code_points(current);
    515515                        continue;
    516516                }
     
    518518                if (ch == U_DELETE) {
    519519                        /* Delete */
    520                         if (position == wstr_length(current))
     520                        if (position == wstr_code_points(current))
    521521                                continue;
    522522
    523523                        if (wstr_remove(current, position)) {
    524524                                printf("%ls ", current + position);
    525                                 print_cc('\b', wstr_length(current) - position + 1);
     525                                print_cc('\b', wstr_code_points(current) - position + 1);
    526526                        }
    527527                        continue;
     
    531531                        printf("%ls", current + position);
    532532                        position++;
    533                         print_cc('\b', wstr_length(current) - position);
    534                 }
    535         }
    536 
    537         if (wstr_length(current) > 0) {
     533                        print_cc('\b', wstr_code_points(current) - position);
     534                }
     535        }
     536
     537        if (wstr_code_points(current) > 0) {
    538538                history_pos++;
    539539                history_pos = history_pos % KCONSOLE_HISTORY;
     
    690690
    691691                if (str_lcmp(hlp->name, cmdline + start,
    692                     max(str_length(hlp->name),
    693                     str_nlength(cmdline + start, (size_t) (end - start)))) == 0) {
     692                    max(str_code_points(hlp->name),
     693                    str_ncode_points(cmdline + start, (size_t) (end - start)))) == 0) {
    694694                        cmd = hlp;
    695695                        break;
     
    826826        while (true) {
    827827                wchar_t *tmp = clever_readline((char *) prompt, stdin, buffer);
    828                 size_t len = wstr_length(tmp);
     828                size_t len = wstr_code_points(tmp);
    829829                if (!len)
    830830                        continue;
Note: See TracChangeset for help on using the changeset viewer.