/usr/include/mimetic/strutils.h is in libmimetic-dev 0.9.8-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | /***************************************************************************
copyright : (C) 2002-2008 by Stefano Barbato
email : stefano@codesink.org
$Id: strutils.h,v 1.10 2008-10-07 11:06:26 tat Exp $
***************************************************************************/
#ifndef _MIMETIC_STRINGUTILS_H_
#define _MIMETIC_STRINGUTILS_H_
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstring>
namespace mimetic
{
extern const std::string nullstring;
struct ichar_traits : public std::char_traits<char>
{
static bool eq (const char_type & c1, const char_type& c2)
{ return (toupper(c1) == toupper(c2)); }
static bool ne (const char_type& c1, const char_type& c2)
{ return (toupper(c1) != toupper(c2)); }
static bool lt (const char_type& c1, const char_type& c2)
{ return (toupper(c1) < toupper(c2)); }
static int compare (const char_type* s1, const char_type* s2, size_t n)
{
for(size_t i=0; i < n; ++i)
if(toupper(s1[i]) != toupper(s2[i]))
return (toupper(s1[i]) < toupper(s2[i])) ?-1: 1;
return 0;
}
static const char* find( const char* s, int n, char a )
{
while( n-- > 0 && tolower(*s) != tolower(a) )
++s;
return s;
}
};
//typedef std::istring <char, ichar_traits> istring;
using std::string;
struct istring: public string
{
istring()
{}
//typedef std::string::allocator_type allocator_type;
istring(const std::string& right)
: string(right)
{}
explicit istring(const allocator_type& al)
: string(al)
{}
istring(const istring& right)
: string(right)
{}
istring(const istring& right, size_type roff, size_type count = npos)
: string(right, roff, count)
{}
istring(const istring& right, size_type roff, size_type count,
const allocator_type& al)
: string(right, roff, count, al)
{}
istring(const value_type *ptr, size_type count)
: string(ptr, count)
{}
istring(const value_type *ptr, size_type count,const allocator_type& al)
: string(ptr, count, al)
{}
istring(const value_type *ptr)
: string(ptr)
{}
istring(const value_type *ptr,const allocator_type& al)
: string(ptr, al)
{}
istring(size_type count, value_type ch)
: string(count,ch)
{}
istring(size_type count, value_type ch,const allocator_type& al)
: string(count,ch,al)
{}
template <class InIt>
istring(InIt first, InIt last)
: string(first, last)
{}
template <class InIt>
istring(InIt first, InIt last,const allocator_type& al)
: string(first, last, al)
{}
};
inline bool operator==(const istring& is, const std::string& s)
{
return (0 == ichar_traits::compare(is.c_str(),s.c_str(),
std::max(is.length(),s.length())) );
}
inline bool operator!=(const istring& is, const std::string& s)
{
return (0 != ichar_traits::compare(is.c_str(),s.c_str(),
std::max(is.length(),s.length())) );
}
inline bool operator!=(const istring& is, const char* str)
{
return (0 != ichar_traits::compare(is.c_str(),str,
std::max(is.length(),::strlen(str))) );
}
inline bool operator==(const istring& is, const char* str)
{
return (0 == ichar_traits::compare(is.c_str(),str,
std::max(is.length(),::strlen(str))) );
}
inline std::string dquoted(const std::string& s)
{
return "\"" + s + "\"";
}
inline std::string parenthed(const std::string& s)
{
return "(" + s + ")";
}
/// removes double quotes
inline std::string remove_dquote(const std::string& s)
{
int len = s.length();
if( len < 2)
return s;
if(s[0] == '"' && s[len-1] == '"')
return std::string(s, 1, len-2);
return s;
}
/**
* returns the \e canonical representation of \p s (see RFC822)
* if \p no_ws is true removes all blanks from the resulting string
*/
std::string canonical(const std::string& s, bool no_ws = false);
/// removes leading and trailing blanks
inline std::string remove_external_blanks(const std::string& in)
{
if(!in.length())
return in;
std::string s = in;
int beg = 0, end = s.length();
for(; beg < end; ++beg)
if(s[beg] != ' ' && s[beg] != '\t')
break;
end = s.length() - 1;
for(; end > beg; --end)
if(s[end] != ' ' && s[end] != '\t')
break;
s.assign(std::string(s, beg, end - beg + 1));
return s;
}
}
#endif
|