~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/common/bspf.hxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-06-02 07:33:16 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20120602073316-20r4hr32t4oj36u9
Tags: 3.7-1
* New upstream version.
* Update description and documentation with new features in 3.7, notably
  Blargg TV filters (replacing the filters available in versions 3.4.1
  and earlier).
* Switch to debhelper compatibility level 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
// See the file "License.txt" for information on usage and redistribution of
15
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
16
//
17
 
// $Id: bspf.hxx 2318 2011-12-31 21:56:36Z stephena $
 
17
// $Id: bspf.hxx 2468 2012-05-12 22:21:59Z stephena $
18
18
//============================================================================
19
19
 
20
20
#ifndef BSPF_HXX
25
25
  that need to be defined for different operating systems.
26
26
 
27
27
  @author Bradford W. Mott
28
 
  @version $Id: bspf.hxx 2318 2011-12-31 21:56:36Z stephena $
 
28
  @version $Id: bspf.hxx 2468 2012-05-12 22:21:59Z stephena $
29
29
*/
30
30
 
31
31
#ifdef HAVE_INTTYPES
121
121
template<typename T> inline T BSPF_abs (T x) { return (x>=0) ? x : -x; }
122
122
template<typename T> inline T BSPF_min (T a, T b) { return (a<b) ? a : b; }
123
123
template<typename T> inline T BSPF_max (T a, T b) { return (a>b) ? a : b; }
 
124
template<typename T> inline T BSPF_clamp (T a, T l, T u) { return (a<l) ? l : (a>u) ? u : a; }
124
125
 
125
126
// Convert integer to string
126
127
inline string BSPF_toString(int num)
130
131
  return buf.str();
131
132
}
132
133
 
 
134
// Test whether two characters are equal (case insensitive)
 
135
static bool BSPF_equalsIgnoreCaseChar(char ch1, char ch2)
 
136
{
 
137
  return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
 
138
}
 
139
// Find location (if any) of the second string within the first,
 
140
// starting from 'startpos' in the first string
 
141
inline size_t BSPF_findIgnoreCase(const string& s1, const string& s2, int startpos = 0)
 
142
{
 
143
  string::const_iterator pos = std::search(s1.begin()+startpos, s1.end(),
 
144
    s2.begin(), s2.end(), BSPF_equalsIgnoreCaseChar);
 
145
  return pos == s1.end() ? string::npos : pos - (s1.begin()+startpos);
 
146
}
 
147
 
133
148
// Test whether two strings are equal (case insensitive)
134
149
inline bool BSPF_equalsIgnoreCase(const string& s1, const string& s2)
135
150
{
150
165
  return BSPF_strncasecmp(s1, s2, strlen(s2)) == 0;
151
166
}
152
167
 
153
 
// Test whether two characters are equal (case insensitive)
154
 
static bool BSPF_equalsIgnoreCaseChar(char ch1, char ch2)
155
 
{
156
 
  return toupper((unsigned char)ch1) == toupper((unsigned char)ch2);
157
 
}
158
 
// Find location (if any) of the second string within the first
159
 
inline size_t BSPF_findIgnoreCase(const string& s1, const string& s2)
160
 
{
161
 
  string::const_iterator pos = std::search(s1.begin(), s1.end(),
162
 
    s2.begin(), s2.end(), BSPF_equalsIgnoreCaseChar);
163
 
  return pos == s1.end() ? string::npos : pos - s1.begin();
 
168
// Test whether the first string ends with the second one (case insensitive)
 
169
inline bool BSPF_endsWithIgnoreCase(const string& s1, const string& s2)
 
170
{
 
171
  return (s1.length() >= s2.length()) ?
 
172
      (BSPF_findIgnoreCase(s1, s2, s1.length() - s2.length()) != string::npos) :
 
173
      false;
164
174
}
165
175
 
166
176
static const string EmptyString("");