pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*-   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin.cmod,v 1.121 2003/02/18 17:33:07 marcus Exp $ + || $Id: builtin.cmod,v 1.122 2003/02/18 23:01:41 marcus Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "opcodes.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"
pike.git/src/builtin.cmod:2260:    pop_stack();       f_single_string_replace_create(i);    }   }      /*! @endclass    */      /*! @class Bootstring +  *! +  *! This class implements the "Bootstring" string transcoder described in +  *! @url{http://www.ietf.org/internet-drafts/draft-ietf-idn-punycode-03.txt@}.    */   PIKECLASS bootstring   {    CVAR INT_TYPE base, tmin, tmax, skew, damp;    CVAR INT_TYPE initial_bias, initial_n;    CVAR p_wchar2 delim;    PIKEVAR string digits;       static INT_TYPE bootstring_cp_to_digit(p_wchar2 ch)    {
pike.git/src/builtin.cmod:2299:    else    delta >>= 1;    delta += delta / numpoints;    while (delta > limit) {    delta /= a;    k += b;    }    return k + (a + 1)*delta / (delta + bs->skew);    }    +  /*! @decl string decode(string s) +  *! +  *! Decodes a Bootstring encoded string of "basic" code points back +  *! to the original string space. +  */    PIKEFUN string decode(string s)    {    struct bootstring_struct *bs = THIS;    INT_TYPE n = bs->initial_n;    INT_TYPE i = 0;    INT_TYPE bias = bs->initial_bias;    ptrdiff_t pos, input_left;    PCHARP input;    struct string_builder output;    init_string_builder( &output,0 );
pike.git/src/builtin.cmod:2384:    break;    default:    Pike_fatal("Illegal shift size!\n");    }    i++;    }       RETURN finish_string_builder( &output );    }    +  /*! @decl string encode(string s) +  *! +  *! Encodes a string using Bootstring encoding into a string constisting +  *! only of "basic" code points (< initial_n). +  */    PIKEFUN string encode(string s)    {    struct bootstring_struct *bs = THIS;    INT_TYPE n = bs->initial_n;    INT_TYPE delta = 0;    INT_TYPE bias = bs->initial_bias;    INT_TYPE c, h, b = 0;    ptrdiff_t pos, input_left;    PCHARP input;    struct string_builder output;
pike.git/src/builtin.cmod:2446:    delta = 0;    h++;    }    delta++;    n++;    }       RETURN finish_string_builder( &output );    }    +  /*! @decl void create(int base, int tmin, int tmax, int skew, @ +  *! int damp, int initial_bias, int initial_n, @ +  *! int delim, string digits) +  *! +  *! Creates a Bootstring transcoder instance using the specified parameters. +  *! +  *! @param base +  *! The base used by the variable-length integers. +  *! @param tmin +  *! The minimum threshold digit value for the variable-length integers. +  *! Must be >=0 and <= tmax. +  *! @param tmax +  *! The maximum threshold digit value for the variable-length integers. +  *! Must be <= base-1. +  *! @param skew +  *! The skew term for the bias adapation. Must be >= 1. +  *! @param damp +  *! The damping factor for the bias adaption. Bust be >= 2. +  *! @param initial_bias +  *! The initial bias for the variable-length integer thresholding. +  *! initial_bias % base must be <= base - tmin. +  *! @param initial_n +  *! The first code point outside the "basic" set of code points. +  *! @param delim +  *! The "basic" code point used as the delimiter. +  *! @param digits +  *! The "basic" code points used as digits. The length of the string +  *! should be the same as the base parameter. +  */    PIKEFUN void create( int base, int tmin, int tmax,    int skew, int damp,    int initial_bias, int initial_n,    int delim, string digits ) -  +  flags ID_STATIC;    {    struct bootstring_struct *bs = THIS; -  +  if (base<2) +  Pike_error("Bogus base\n"); +  if (tmin<0 || tmax<tmin || base-1<tmax) +  Pike_error("Parameters violate 0 <= tmin <= tmax <= base-1\n"); +  if (skew < 1) +  Pike_error("Parameters violate skew >= 1\n"); +  if (damp < 2) +  Pike_error("Parameters violate damp >= 2\n"); +  if (initial_bias%base > base-tmin) +  Pike_error("Parameters violate initial_bias%%base <= base-tmin\n"); +  if (digits->len != base) +  Pike_error("Length of digits string does not match base.\n");    bs->base = base; bs->tmin = tmin; bs->tmax = tmax;    bs->skew = skew; bs->damp = damp;    bs->initial_bias = initial_bias; bs->initial_n = initial_n;    bs->delim = delim;    if (bs->digits) {    free_string( bs->digits );    bs->digits = NULL;    }    copy_shared_string( bs->digits, digits );    }