pike.git / lib / modules / String.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/String.pmod/module.pmod:1:   #pike __REAL_VERSION__   #pragma strict_types    + constant Bootstring = __builtin.bootstring;   constant Buffer = __builtin.Buffer; -  - constant count=__builtin.string_count; - constant width=__builtin.string_width; - constant trim_whites = __builtin.string_trim_whites; - constant normalize_space = __builtin.string_normalize_space; - constant trim_all_whites = __builtin.string_trim_all_whites; +    constant Iterator = __builtin.string_iterator; - constant SplitIterator = __builtin.string_split_iterator; +    constant Replace = __builtin.multi_string_replace;   constant SingleReplace = __builtin.single_string_replace; - constant Bootstring = __builtin.bootstring; - constant int2char = int2char; - constant int2hex = int2hex; - constant string2hex = __builtin.string2hex; + constant SplitIterator = __builtin.string_split_iterator; +  + constant count = __builtin.string_count; + constant filter_non_unicode = string_filter_non_unicode;   constant hex2string = __builtin.hex2string; -  + constant int2char = predef::int2char; + constant int2hex = predef::int2hex; + constant normalize_space = __builtin.string_normalize_space; + constant range = __builtin.string_range;   constant secure = __builtin.string_secure;   constant status = __builtin.string_status; -  + constant trim = __builtin.string_trim; + /* deprecated */ constant trim_all_whites = __builtin.string_trim; + constant trim_whites = __builtin.string_trim_whites; + constant width = __builtin.string_width;      constant __HAVE_SPRINTF_STAR_MAPPING__ = 1;   constant __HAVE_SPRINTF_NEGATIVE_F__ = 1;    -  + #if constant(predef::string2hex) + /* NB: This module is used from the precompiler, and may thus be used +  * with older versions of Pike. +  */ + constant string2hex = predef::string2hex; + #else + /* NB: Intentionally uses integer ranges instead of 7bit/8bit +  * for improved backward compat. +  */ + string(0..127) string2hex(string(0..255) s) + { +  return sprintf("%{%02x%}", (array(int(0..255)))s); + } + #endif +    //! This function implodes a list of words to a readable string, e.g.   //! @expr{({"straw","berry","pie"})@} becomes   //! @expr{"straw, berry and pie"@}. If the separator is omitted, the   //! default is @expr{"and"@}. If the words are numbers they are   //! converted to strings first.   //!   //! @seealso   //! @[`*()]   //!   string implode_nicely(array(string|int|float) foo, string|void separator)
pike.git/lib/modules/String.pmod/module.pmod:208:    // Then we can calculate the next row    // lev_i+1 = ( lev_ai+1,bj(|ai|+1,j) for j=0..|b| )    // from the above formula.       // Initialize lev_i for the empty string a0, i.e., |a0| = 0.    // You need |bj| = j edit operations (deleting each character from bj) to    // get from bj to a0.    // Thus lev_0[j] = j for j=0..|b|:    int(0..2147483647) len = strlen(b);    -  if( len == 2147483647 ) +  if( len > 2147483646 )    error("Too large string.\n");       ++len; -  +     array(int) lev_i = enumerate(len);    for (int i = 0; i < strlen(a); i++)    {    // To calculate the next row (i+1): copy lev_i:    array(int) lev_p = copy_value(lev_i);       // First element of lev_i+1 is lev_ai+1,bj(|ai|+1,0):    // the edit distance is deleting (i+1) chars from a to match empty b:    lev_i[0] = i + 1;       // Use the mathematical formula to fill in the rest of the row:    for (int j = 0; j < strlen(b); j++)    { -  int cost = (a[i] == b[j]) ? 0 : 1; +  int cost = (a[i] != b[j]);    lev_i[j + 1] = min(lev_i[j] + 1,    lev_p[j + 1] + 1,    lev_p[j] + cost);    }    }       // Now the Levenshtein distance is the last element in the last row:    return lev_i[strlen(b)];   }   
pike.git/lib/modules/String.pmod/module.pmod:299:   //! but we have chosen to keep the old notation for a while.   //! The function knows about the quantifiers kilo, mega, giga,   //! tera, peta, exa, zetta and yotta.   string int2size( int size )   {    if(size<0)    return "-" + int2size(-size);    if(size==1) return "1 byte";    int oldmask = -1;    int mask = -1024; -  int no; -  int val = size; +  int(0..) no; +  int(0..) val = [int(0..)]size;    while (size & mask) {    if (++no == sizeof(prefix))    return sprintf("%d %s", val, prefix[-1]);    oldmask = mask;    mask <<= 10;    val >>= 10;    }       int decimal;    if (!(decimal = (size & ~oldmask))) return sprintf("%d %s", val, prefix[no]);       // Convert the decimal to base 10. -  decimal += 1<<(no*10 - 4); // Rounding. +  // NB: no >= 1 since otherwise ~oldmask == ~-1 == 0 and we return above. +  decimal += 1<<[int(6..)](no*10 - 4); // Rounding.    decimal *= 5; -  decimal >>= no*10 - 1; +  decimal >>= [int(9..)](no*10 - 1);       if (decimal == 10) {    val++;    decimal = 0;    }       return sprintf("%d.%d %s", val, decimal, prefix[no]);   }      //! Expands tabs in a string to ordinary spaces, according to common