Miscellaneous utility functions.
parent
7db6d2eadf
commit
2849b6f09a
|
@ -0,0 +1,31 @@
|
|||
// util.cpp
|
||||
//
|
||||
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
|
||||
//
|
||||
// Miscellaneous useful functions.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#include "util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int compareIgnoringCase(const string& s1, const string& s2)
|
||||
{
|
||||
string::const_iterator i1 = s1.begin();
|
||||
string::const_iterator i2 = s2.begin();
|
||||
|
||||
while (i1 != s1.end() && i2 != s2.end())
|
||||
{
|
||||
if (toupper(*i1) != toupper(*i2))
|
||||
return (toupper(*i1) < toupper(*i2)) ? -1 : 1;
|
||||
++i1;
|
||||
++i2;
|
||||
}
|
||||
|
||||
return s2.size() - s1.size();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// util.h
|
||||
//
|
||||
// Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
|
||||
//
|
||||
// Miscellaneous useful functions.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
extern int compareIgnoringCase(const std::string& s1, const std::string& s2);
|
||||
|
||||
#endif // _UTIL_H_
|
Loading…
Reference in New Issue