1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  *
3  *   astyle.h
4  *
5  *   This file is a part of "Artistic Style" - an indentation and
6  *   reformatting tool for C, C++, C# and Java source files.
7  *   http://astyle.sourceforge.net
8  *
9  *   The "Artistic Style" project, including all files needed to
10  *   compile it, is free software; you can redistribute it and/or
11  *   modify it under the terms of the GNU Lesser General Public
12  *   License as published by the Free Software Foundation; either
13  *   version 2.1 of the License, or (at your option) any later
14  *   version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU Lesser General Public License for more details.
20  *
21  *   You should have received a copy of the GNU Lesser General Public
22  *   License along with this project; if not, write to the
23  *   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  *   Boston, MA  02110-1301, USA.
25  *
26  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
27  */
28 
29  /*
30  	2008-01-26 Patches by Massimo Del Fedele :
31  		- modified sources to use Ultimate++ containers instead std:: ones
32  		- fixed memory leaks based on bug report 1804791 submitted by Eran Ifrah
33  		- modified to work with unicode
34  */
35 #include "ASStringTools.hpp"
36 
37 ///////////////////////////////////////////////////////////////////////////////////////////
38 // Replaces a chunk in a string with a new string
ASString_Replace(WString & s,int Pos,int Len,WString const & newString)39 void ASString_Replace(WString &s, int Pos, int Len, WString const &newString)
40 {
41 	if(Pos < 0 || Pos >= s.GetCount())
42 		return;
43 	s.Remove(Pos, Len);
44 	s.Insert(Pos, newString);
45 
46 } // END ASString_Replace()
47 
48 ///////////////////////////////////////////////////////////////////////////////////////////
49 // Find first character in a string *not* contained in another string
ASString_Find_First_Not_Of(WString const & s,WString const & Pattern,int pos)50 int ASString_Find_First_Not_Of(WString const &s, WString const &Pattern, int pos)
51 {
52 	if(pos < 0 || pos >= s.GetCount())
53 		return -1;
54 	int len = s.GetCount();
55 	while(pos < len && Pattern.Find(s[pos]) != -1)
56 		pos++;
57 	if(pos < len)
58 		return pos;
59 	else
60 		return -1;
61 
62 } // END ASString_Find_First_Not_Of()
63 
64 ///////////////////////////////////////////////////////////////////////////////////////////
65 // Find last character in a string *not* contained in another string
ASString_Find_Last_Not_Of(WString const & s,WString const & Pattern,int pos)66 int ASString_Find_Last_Not_Of(WString const &s, WString const &Pattern, int pos)
67 {
68 	if(pos < 0 || pos >= s.GetCount())
69 		pos = s.GetCount() -1;
70 	while(pos > 0 && Pattern.Find(s[pos]) != -1)
71 		pos--;
72 	return pos;
73 
74 } // END ASString_Find_Last_Not_Of()
75 
76 ///////////////////////////////////////////////////////////////////////////////////////////
77 // Finds a substring starting at the end of a given string
ASString_ReverseFind(WString const & s,WString const & Pattern)78 int ASString_ReverseFind(WString const &s, WString const &Pattern)
79 {
80 	int pos = -1;
81 	int k = 0;
82 	while( (k = s.Find(Pattern, k)) >= 0)
83 		pos = k++;
84 	return pos;
85 
86 } // END ASString_ReverseFind()
87