pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:430:    ares += ({apart}), bres += ({bpart}), cres += ({cpart});    }       return ({ares, bres, cres});   }      //! Sort without respect to number formatting (most notably leading   //! zeroes).   int(-1..1) dwim_sort_func(string a, string b)   { -  if (a==b) return 0; -  array aa=({}), bb=({}); -  int state, oi; +  if( a==b ) return 0;    -  for( int i = 0; i<sizeof(a); i++ ) -  if( (<'0','1','2','3','4','5','6','7','8','9'>)[a[i]] != state ) +  string a_int,b_int; +  string a_str,b_str; +  while(1)    { -  state = !state; -  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..] }); +  sscanf(a, "%[0-9]%[^0-9]%s", a_int,a_str,a); +  sscanf(b, "%[0-9]%[^0-9]%s", b_int,b_str,b);    -  +  // Need only be done first iteration +  if( !sizeof(a_int) ^ !sizeof(b_int) ) +  return sizeof(a_int) ? -1 : 1;    -  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 ) +  if( a_int != b_int )    { -  state = !state; -  if( state ) -  bb += ({ b[oi..i-1] }); -  else -  bb += ({ (int)b[oi..i-1] }); -  oi = i; +  int ai = (int)a_int; +  int bi = (int)b_int; +  if( ai!=bi ) +  return ai<bi ? -1 : 1;    } -  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( a_str != b_str ) +  return a_str<b_str ? -1 : 1;    -  if( aa[i] < bb[i] ) return -1; -  if( aa[i] > bb[i] ) return 1; +  if( !sizeof(a) || !sizeof(b) ) +  { +  if( sizeof(a) ) return 1; +  if( sizeof(b) ) return -1; +  return 0;    } -  -  // Either equal, or bb is longer. -  -  return [int(-1..1)]-(sizeof(aa)<sizeof(bb)); +     } -  + }      //! 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(-1..1) 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);