Miscellaneous utility functions.

pull/3/head
Chris Laurel 2001-03-17 00:17:44 +00:00
parent 7db6d2eadf
commit 2849b6f09a
2 changed files with 50 additions and 0 deletions

31
src/util.cpp 100644
View File

@ -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();
}

19
src/util.h 100644
View File

@ -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_