Ignore:
File:
1 edited

Legend:

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

    rd066259 r09ab0a9a  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
    32 * Copyright (c) 2005 Martin Decky
    43 * Copyright (c) 2008 Jiri Svoboda
     
    3433 * @{
    3534 */
    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  *
     35/** @file
    10636 */
    10737
    10838#include <str.h>
    109 
     39#include <stddef.h>
     40#include <stdint.h>
     41#include <stdlib.h>
    11042#include <assert.h>
    11143#include <ctype.h>
    11244#include <errno.h>
    113 #include <stdbool.h>
    114 #include <stddef.h>
    115 #include <stdint.h>
    116 #include <stdlib.h>
    117 
    11845#include <align.h>
    11946#include <mem.h>
     47#include <limits.h>
    12048
    12149/** Check the condition if wchar_t is signed */
     
    819747        /* There must be space for a null terminator in the buffer. */
    820748        assert(size > 0);
    821         assert(src != NULL);
    822749
    823750        size_t src_off = 0;
     
    13841311{
    13851312        size_t size = str_size(src) + 1;
    1386         char *dest = malloc(size);
    1387         if (!dest)
    1388                 return NULL;
     1313        char *dest = (char *) malloc(size);
     1314        if (dest == NULL)
     1315                return (char *) NULL;
    13891316
    13901317        str_cpy(dest, size, src);
     
    14181345                size = n;
    14191346
    1420         char *dest = malloc(size + 1);
    1421         if (!dest)
    1422                 return NULL;
     1347        char *dest = (char *) malloc(size + 1);
     1348        if (dest == NULL)
     1349                return (char *) NULL;
    14231350
    14241351        str_ncpy(dest, size + 1, src, size);
Note: See TracChangeset for help on using the changeset viewer.