| 1 |
////////////////////////////////////////////////////////////////////////////// |
| 2 |
////////////////////////////////////////////////////////////////////////////// |
| 3 |
// |
| 4 |
// copyright : (C) 2008 by Eran Ifrah |
| 5 |
// file name : stringaccessor.cpp |
| 6 |
// |
| 7 |
// ------------------------------------------------------------------------- |
| 8 |
// A |
| 9 |
// _____ _ _ _ _ |
| 10 |
// / __ \ | | | | (_) | |
| 11 |
// | / \/ ___ __| | ___| | _| |_ ___ |
| 12 |
// | | / _ \ / _ |/ _ \ | | | __/ _ ) |
| 13 |
// | \__/\ (_) | (_| | __/ |___| | || __/ |
| 14 |
// \____/\___/ \__,_|\___\_____/_|\__\___| |
| 15 |
// |
| 16 |
// F i l e |
| 17 |
// |
| 18 |
// This program is free software; you can redistribute it and/or modify |
| 19 |
// it under the terms of the GNU General Public License as published by |
| 20 |
// the Free Software Foundation; either version 2 of the License, or |
| 21 |
// (at your option) any later version. |
| 22 |
// |
| 23 |
////////////////////////////////////////////////////////////////////////////// |
| 24 |
////////////////////////////////////////////////////////////////////////////// |
| 25 |
#include "stringaccessor.h" |
| 26 |
|
| 27 |
StringAccessor::StringAccessor(const wxString &str) |
| 28 |
: m_str(str.c_str()) |
| 29 |
{ |
| 30 |
} |
| 31 |
|
| 32 |
StringAccessor::~StringAccessor() |
| 33 |
{ |
| 34 |
} |
| 35 |
|
| 36 |
char StringAccessor::safeAt(size_t pos) |
| 37 |
{ |
| 38 |
if( pos >= m_str.size() ) { |
| 39 |
return 0; |
| 40 |
} |
| 41 |
|
| 42 |
return m_str.at(pos); |
| 43 |
} |
| 44 |
|
| 45 |
bool StringAccessor::isWordChar(char ch) |
| 46 |
{ |
| 47 |
int ascii_value = (int)ch; |
| 48 |
if( (ascii_value >= 48 && ascii_value <= 57) || // 0-9 |
| 49 |
(ascii_value >= 65 && ascii_value <= 90) || // A-Z |
| 50 |
(ascii_value >= 97 && ascii_value <= 122) || // a-z |
| 51 |
(ascii_value == 95)) { // _ |
| 52 |
return true; |
| 53 |
} |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
bool StringAccessor::match(const char* str, size_t from) |
| 58 |
{ |
| 59 |
size_t size = strlen(str); |
| 60 |
for(size_t i=0; i<size; i++) { |
| 61 |
if(str[i] != safeAt(from + i)) { |
| 62 |
return false; |
| 63 |
} |
| 64 |
} |
| 65 |
return true; |
| 66 |
} |