2005-09-20 13:26:39 +00:00
|
|
|
/** \file util.h
|
2012-11-18 10:23:22 +00:00
|
|
|
Generic utilities library.
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
|
|
|
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_UTIL_H
|
|
|
|
#define FISH_UTIL_H
|
|
|
|
|
|
|
|
#include <wchar.h>
|
2005-10-12 10:34:21 +00:00
|
|
|
#include <stdarg.h>
|
2006-01-26 12:21:34 +00:00
|
|
|
#include <unistd.h>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Returns the larger of two ints
|
|
|
|
*/
|
2012-07-29 00:49:46 +00:00
|
|
|
template<typename T>
|
2012-11-19 00:30:30 +00:00
|
|
|
static inline T maxi(T a, T b)
|
2012-07-29 00:49:46 +00:00
|
|
|
{
|
|
|
|
return a>b?a:b;
|
|
|
|
}
|
2005-10-26 14:48:23 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
|
|
|
Returns the smaller of two ints
|
|
|
|
*/
|
2012-07-29 00:49:46 +00:00
|
|
|
template<typename T>
|
2012-11-19 00:30:30 +00:00
|
|
|
static inline T mini(T a, T b)
|
2012-07-29 00:49:46 +00:00
|
|
|
{
|
|
|
|
return a<b?a:b;
|
|
|
|
}
|
2005-10-26 14:48:23 +00:00
|
|
|
|
2005-09-20 13:26:39 +00:00
|
|
|
/**
|
2006-10-01 15:59:18 +00:00
|
|
|
Compares two wide character strings with an (arguably) intuitive
|
|
|
|
ordering.
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
This function tries to order strings in a way which is intuitive to
|
|
|
|
humans with regards to sorting strings containing numbers.
|
|
|
|
|
|
|
|
Most sorting functions would sort the strings 'file1.txt'
|
|
|
|
'file5.txt' and 'file12.txt' as:
|
|
|
|
|
|
|
|
file1.txt
|
|
|
|
file12.txt
|
|
|
|
file5.txt
|
|
|
|
|
|
|
|
This function regards any sequence of digits as a single entity
|
|
|
|
when performing comparisons, so the output is instead:
|
|
|
|
|
|
|
|
file1.txt
|
|
|
|
file5.txt
|
|
|
|
file12.txt
|
|
|
|
|
|
|
|
Which most people would find more intuitive.
|
|
|
|
|
2005-10-26 14:48:23 +00:00
|
|
|
This won't return the optimum results for numbers in bases higher
|
|
|
|
than ten, such as hexadecimal, but at least a stable sort order
|
|
|
|
will result.
|
2006-10-01 15:59:18 +00:00
|
|
|
|
|
|
|
This function performs a two-tiered sort, where difference in case
|
|
|
|
and in number of leading zeroes in numbers only have effect if no
|
|
|
|
other differences between strings are found. This way, a 'file1'
|
|
|
|
and 'File1' will not be considered identical, and hence their
|
|
|
|
internal sort order is not arbitrary, but the names 'file1',
|
|
|
|
'File2' and 'file3' will still be sorted in the order given above.
|
2005-09-20 13:26:39 +00:00
|
|
|
*/
|
2012-11-19 00:30:30 +00:00
|
|
|
int wcsfilecmp(const wchar_t *a, const wchar_t *b);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the current time in microseconds since Jan 1, 1970
|
|
|
|
*/
|
|
|
|
long long get_time();
|
2005-10-04 15:11:39 +00:00
|
|
|
|
|
|
|
#endif
|