33 #ifdef ALPHANUM_LOCALE
54 #ifdef ALPHANUM_LOCALE
56 bool alphanum_isdigit(
int c)
65 bool alphanum_isdigit(
const char c)
67 return c>=
'0' && c<=
'9';
86 int alphanum_impl(
const char *l,
const char *r)
88 enum mode_t { STRING, NUMBER } mode=STRING;
95 while((l_char=*l) && (r_char=*r))
98 const bool l_digit=alphanum_isdigit(l_char), r_digit=alphanum_isdigit(r_char);
100 if(l_digit && r_digit)
106 if(l_digit)
return -1;
108 if(r_digit)
return +1;
110 const int diff=l_char - r_char;
112 if(diff != 0)
return diff;
120 #ifdef ALPHANUM_LOCALE
123 unsigned long l_int=strtoul(l, &end, 0);
127 unsigned long r_int=strtoul(r, &end, 0);
131 unsigned long l_int=0;
132 while(*l && alphanum_isdigit(*l))
135 l_int=l_int*10 + *l-
'0';
140 unsigned long r_int=0;
141 while(*r && alphanum_isdigit(*r))
144 r_int=r_int*10 + *r-
'0';
150 const long diff=l_int-r_int;
174 template <
typename lT,
typename rT>
178 std::clog <<
"alphanum_comp<" <<
typeid(left).name() <<
"," <<
typeid(right).name() <<
"> " << left <<
"," << right << std::endl;
180 std::ostringstream l; l << left;
181 std::ostringstream r; r << right;
182 return alphanum_impl(l.str().c_str(), r.str().c_str());
193 int alphanum_comp<std::string>(
const std::string& l,
const std::string& r)
196 std::clog <<
"alphanum_comp<std::string,std::string> " << l <<
"," << r << std::endl;
198 return alphanum_impl(l.c_str(), r.c_str());
219 std::clog <<
"alphanum_comp<char*,char*> " << l <<
"," << r << std::endl;
221 return alphanum_impl(l, r);
229 std::clog <<
"alphanum_comp<const char*,const char*> " << l <<
"," << r << std::endl;
231 return alphanum_impl(l, r);
239 std::clog <<
"alphanum_comp<char*,const char*> " << l <<
"," << r << std::endl;
241 return alphanum_impl(l, r);
249 std::clog <<
"alphanum_comp<const char*,char*> " << l <<
"," << r << std::endl;
251 return alphanum_impl(l, r);
258 std::clog <<
"alphanum_comp<std::string,char*> " << l <<
"," << r << std::endl;
260 return alphanum_impl(l.c_str(), r);
267 std::clog <<
"alphanum_comp<char*,std::string> " << l <<
"," << r << std::endl;
269 return alphanum_impl(l, r.c_str());
276 std::clog <<
"alphanum_comp<std::string,const char*> " << l <<
"," << r << std::endl;
278 return alphanum_impl(l.c_str(), r);
285 std::clog <<
"alphanum_comp<const char*,std::string> " << l <<
"," << r << std::endl;
287 return alphanum_impl(l, r.c_str());
351 std::string str(
"Alpha 2");
362 std::set<std::string, doj::alphanum_less<std::string> > s;
363 s.insert(
"Xiph Xlater 58");
364 s.insert(
"Xiph Xlater 5000");
365 s.insert(
"Xiph Xlater 500");
366 s.insert(
"Xiph Xlater 50");
367 s.insert(
"Xiph Xlater 5");
368 s.insert(
"Xiph Xlater 40");
369 s.insert(
"Xiph Xlater 300");
370 s.insert(
"Xiph Xlater 2000");
371 s.insert(
"Xiph Xlater 10000");
372 s.insert(
"QRS-62F Intrinsia Machine");
373 s.insert(
"QRS-62 Intrinsia Machine");
374 s.insert(
"QRS-60F Intrinsia Machine");
375 s.insert(
"QRS-60 Intrinsia Machine");
376 s.insert(
"Callisto Morphamax 7000 SE2");
377 s.insert(
"Callisto Morphamax 7000 SE");
378 s.insert(
"Callisto Morphamax 7000");
379 s.insert(
"Callisto Morphamax 700");
380 s.insert(
"Callisto Morphamax 600");
381 s.insert(
"Callisto Morphamax 5000");
382 s.insert(
"Callisto Morphamax 500");
383 s.insert(
"Callisto Morphamax");
384 s.insert(
"Alpha 2A-900");
385 s.insert(
"Alpha 2A-8000");
386 s.insert(
"Alpha 2A");
387 s.insert(
"Alpha 200");
389 s.insert(
"Alpha 100");
390 s.insert(
"Allegia 60 Clasteron");
391 s.insert(
"Allegia 52 Clasteron");
392 s.insert(
"Allegia 51B Clasteron");
393 s.insert(
"Allegia 51 Clasteron");
394 s.insert(
"Allegia 500 Clasteron");
395 s.insert(
"Allegia 50 Clasteron");
396 s.insert(
"40X Radonius");
397 s.insert(
"30X Radonius");
398 s.insert(
"20X Radonius Prime");
399 s.insert(
"20X Radonius");
400 s.insert(
"200X Radonius");
401 s.insert(
"10X Radonius");
402 s.insert(
"1000X Radonius Maximus");
404 std::copy(s.begin(), s.end(), std::ostream_iterator<std::string>(std::cout,
"\n"));
407 typedef std::map<std::string, int, doj::alphanum_less<std::string> > m_t;
433 for(m_t::iterator i=m.begin(); i!=m.end(); ++i)
434 std::cout << i->first <<
'\t' << i->second << std::endl;
437 std::vector<std::string> v;
439 std::copy(s.rbegin(), s.rend(), std::back_inserter(v));
443 std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout,
"\n"));