pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:452:   // " x=%d l=%d:%d r=%d:%d \n",@res[-1],x,l,lpos,r,rpos));       rpos+=x;    lpos+=x;    n+=x;    }       return transpose(res);   }    - //! sort with care of numerical sort: - //! @tt{"abc4def"@} before @tt{"abc30def"@}. + //! Sort without   int dwim_sort_func(string a, string b)   {    if (a==b) return 0; -  +  array aa=({}), bb=({}); +  int state, oi;    -  string a2="",b2=""; -  int a1,b1; -  sscanf(a, "%s%d%s", a, a1, a2); -  sscanf(b, "%s%d%s", b, b1, b2); -  if (a > b) return 1; -  if (a < b) return 0; -  if (a1>b1) return 1; -  if (a1<b1) return 0; -  if (a2==b2) return 0; -  return dwim_sort_func(a2,b2); +  for( int i = 0; i<sizeof(a); i++ ) +  if( (<'0','1','2','3','4','5','6','7','8','9'>)[a[i]] != state ) +  { +  state = !state; +  if( i ) +  if( state ) +  aa += ({ a[oi..i-1] }); +  else +  aa += ({ (int)a[oi..i-1] }); +  oi = i;    } -  +  if( state ) +  aa += ({ (int)a[oi..] }); +  else +  aa += ({ a[oi..] });    - //! sort with no notice of contents in paranthesis, - //! no care of case either +  +  oi = state = 0; +  +  for( int i = 0; i<sizeof(b); i++ ) +  if( (<'0','1','2','3','4','5','6','7','8','9'>)[b[i]] != state ) +  { +  state = !state; +  if( i ) +  if( state ) +  bb += ({ b[oi..i-1] }); +  else +  bb += ({ (int)b[oi..i-1] }); +  oi = i; +  } +  if( state ) +  bb += ({ (int)b[oi..] }); +  else +  bb += ({ b[oi..] }); +  +  for( int i = 0; i<sizeof( aa ); i++ ) +  { +  if( i >= sizeof( bb ) ) return 1; // a is definately bigger. +  +  if( aa[i] < bb[i] ) return -1; +  if( aa[i] > bb[i] ) return 1; +  } +  +  return 0; + } +  + //! Sort comparison function that does not care about case, nor about + //! the contents of any parts of the string enclosed with '()' + //! + //! Example: "Foo (bar)" is given the same weight as "foo (really!)"   int lyskom_sort_func(string a,string b)   {    string a0=a,b0=b;    a=replace(lower_case(a),"][\\}{|"/1,"åäöåäö"/1);    b=replace(lower_case(b),"][\\}{|"/1,"åäöåäö"/1);       while (sscanf(a0=a,"%*[ \t](%*[^)])%*[ \t]%s",a)==4 && a0!=a);    while (sscanf(b0=b,"%*[ \t](%*[^)])%*[ \t]%s",b)==4 && b0!=b);    a0=b0="";    sscanf(a,"%[^ \t]%*[ \t](%*[^)])%*[ \t]%s",a,a0);
pike.git/lib/modules/Array.pmod:497:   }      //! Flatten a multi-dimensional array to a one-dimensional array.   array flatten(array a)   {    array ret=({});    foreach(a, mixed b) ret+=arrayp(b)?flatten([array]b):({b});    return ret;   }    - //! Sum the elements of an array + //! Sum the elements of an array using `+   mixed sum(array a)   {   // 1000 is a safe stack limit    if (sizeof(a)<1000)    return `+(@a);    else    {    mixed mem=`+(@a[..999]);    int j=1000;    array v;    while (sizeof(v=a[j..j+999]))    mem=`+(mem,@v),j+=1000;    return mem;    }   }    - //! Perform uniq on an array, - //! aabbbcaababb -> abcabab -  + //! Perform the same action as the Unix uniq command on an array, + //! aabbbcaababb -> abcabab. + //! + //! See also the @[uniq] function.   array uniq2(array a)   {    array res;    mixed last;    if (!sizeof(a)) return ({});    res=({last=a[0]});    foreach (a,mixed v)    if (v!=last) last=v,res+=({v});    return res;   }
pike.git/lib/modules/Array.pmod:539:   //! a zero_type argument makes the empty array:   //!   // mark this with the right stuff, someone: /Mirar   //! zero_type(x): arrayify(x) => ({})   //! arrayp(x) arrayify(x) => x   //! else arrayify(x) => ({x})   //!   //! This is useful when something is either an array or   //! a basic datatype, for instance in headers from the MIME   //! module or Protocols.HTTP.Server. -  +    array arrayify(void|array|mixed z)   {    if (zero_type(z)) return ({});    if (arrayp(z)) return z;    return ({z});   }