Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/str.c

    r09ab0a9a rd066259  
    11/*
     2 * Copyright (c) 2001-2004 Jakub Jermar
    23 * Copyright (c) 2005 Martin Decky
    34 * Copyright (c) 2008 Jiri Svoboda
     
    3334 * @{
    3435 */
    35 /** @file
     36
     37/**
     38 * @file
     39 * @brief String functions.
     40 *
     41 * Strings and characters use the Universal Character Set (UCS). The standard
     42 * strings, called just strings are encoded in UTF-8. Wide strings (encoded
     43 * in UTF-32) are supported to a limited degree. A single character is
     44 * represented as wchar_t.@n
     45 *
     46 * Overview of the terminology:@n
     47 *
     48 *  Term                  Meaning
     49 *  --------------------  ----------------------------------------------------
     50 *  byte                  8 bits stored in uint8_t (unsigned 8 bit integer)
     51 *
     52 *  character             UTF-32 encoded Unicode character, stored in wchar_t
     53 *                        (signed 32 bit integer), code points 0 .. 1114111
     54 *                        are valid
     55 *
     56 *  ASCII character       7 bit encoded ASCII character, stored in char
     57 *                        (usually signed 8 bit integer), code points 0 .. 127
     58 *                        are valid
     59 *
     60 *  string                UTF-8 encoded NULL-terminated Unicode string, char *
     61 *
     62 *  wide string           UTF-32 encoded NULL-terminated Unicode string,
     63 *                        wchar_t *
     64 *
     65 *  [wide] string size    number of BYTES in a [wide] string (excluding
     66 *                        the NULL-terminator), size_t
     67 *
     68 *  [wide] string length  number of CHARACTERS in a [wide] string (excluding
     69 *                        the NULL-terminator), size_t
     70 *
     71 *  [wide] string width   number of display cells on a monospace display taken
     72 *                        by a [wide] string, size_t
     73 *
     74 *
     75 * Overview of string metrics:@n
     76 *
     77 *  Metric  Abbrev.  Type     Meaning
     78 *  ------  ------   ------   -------------------------------------------------
     79 *  size    n        size_t   number of BYTES in a string (excluding the
     80 *                            NULL-terminator)
     81 *
     82 *  length  l        size_t   number of CHARACTERS in a string (excluding the
     83 *                            null terminator)
     84 *
     85 *  width  w         size_t   number of display cells on a monospace display
     86 *                            taken by a string
     87 *
     88 *
     89 * Function naming prefixes:@n
     90 *
     91 *  chr_    operate on characters
     92 *  ascii_  operate on ASCII characters
     93 *  str_    operate on strings
     94 *  wstr_   operate on wide strings
     95 *
     96 *  [w]str_[n|l|w]  operate on a prefix limited by size, length
     97 *                  or width
     98 *
     99 *
     100 * A specific character inside a [wide] string can be referred to by:@n
     101 *
     102 *  pointer (char *, wchar_t *)
     103 *  byte offset (size_t)
     104 *  character index (size_t)
     105 *
    36106 */
    37107
    38108#include <str.h>
     109
     110#include <assert.h>
     111#include <ctype.h>
     112#include <errno.h>
     113#include <stdbool.h>
    39114#include <stddef.h>
    40115#include <stdint.h>
    41116#include <stdlib.h>
    42 #include <assert.h>
    43 #include <ctype.h>
    44 #include <errno.h>
     117
    45118#include <align.h>
    46119#include <mem.h>
    47 #include <limits.h>
    48120
    49121/** Check the condition if wchar_t is signed */
     
    747819        /* There must be space for a null terminator in the buffer. */
    748820        assert(size > 0);
     821        assert(src != NULL);
    749822
    750823        size_t src_off = 0;
     
    13111384{
    13121385        size_t size = str_size(src) + 1;
    1313         char *dest = (char *) malloc(size);
    1314         if (dest == NULL)
    1315                 return (char *) NULL;
     1386        char *dest = malloc(size);
     1387        if (!dest)
     1388                return NULL;
    13161389
    13171390        str_cpy(dest, size, src);
     
    13451418                size = n;
    13461419
    1347         char *dest = (char *) malloc(size + 1);
    1348         if (dest == NULL)
    1349                 return (char *) NULL;
     1420        char *dest = malloc(size + 1);
     1421        if (!dest)
     1422                return NULL;
    13501423
    13511424        str_ncpy(dest, size + 1, src, size);
Note: See TracChangeset for help on using the changeset viewer.