Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditorCalAdr: Implemented priority control
[xestiaab/.git] / source / common / textprocessing.cpp
1 // textprocessing.cpp - Text processing subroutines.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <wx/wx.h>
20 #include <iostream>
21 #include <iomanip>
22 #include <string.h>
23 #include <map>
24 #include "textprocessing.h"
26 void EscapeString(wxString *ReceivedString, bool StripQuotes)
27 {
29         // Escape a string that contains escapable characters.
31         ReceivedString->Replace(wxT("\\"), wxT("\\\\"), TRUE);
32         ReceivedString->Replace(wxT(","), wxT("\\,"), TRUE);
33         ReceivedString->Replace(wxT(";"), wxT("\\;"), TRUE);
34         ReceivedString->Replace(wxT("\r\n"), wxT("\\n"), TRUE);
35         ReceivedString->Replace(wxT("\n"), wxT("\\n"), TRUE);
36         
37         if (StripQuotes == TRUE){
38         
39                 ReceivedString->Replace(wxT("\""), wxT(""), TRUE);
40                 
41         }
43 }
45 void GetEscapeString(wxTextCtrl *TextCtrl, wxString *ProcessString, bool StripQuotes)
46 {
48         // Get an escaped string from a wxTextCtrl.
50         *ProcessString = TextCtrl->GetValue();
51         EscapeString(ProcessString, StripQuotes);
53 }
55 void GetEscapeString(wxComboBox *ComboCtrl, wxString *ProcessString, bool StripQuotes)
56 {
58         // Get an escaped string from a wxComboBox.
60         *ProcessString = ComboCtrl->GetValue();
61         EscapeString(ProcessString, StripQuotes);
63 }
65 void GetEscapeString(wxChoice *ChoiceCtrl, wxString *ProcessString, bool StripQuotes)
66 {
68         // Get an escaped string from a wxChoice.
70         *ProcessString = ChoiceCtrl->GetString(ChoiceCtrl->GetSelection());
71         EscapeString(ProcessString, StripQuotes);
73 }
75 void CaptureString(wxString *ProcessString, bool StripQuotes)
76 {
78         // Capture a string for processing.
80         ProcessString->Replace(wxT("\\n"), wxT("\n"), TRUE);
81         ProcessString->Replace(wxT("\\;"), wxT(";"), TRUE);
82         ProcessString->Replace(wxT("\\,"), wxT(","), TRUE);
83         ProcessString->Replace(wxT("\\\\"), wxT("\\"), TRUE);
84         
85         if (StripQuotes == TRUE){
86         
87                 ProcessString->Replace(wxT("\""), wxT(""), TRUE);
88         
89         }
91 }
93 void ResetUnusedString(wxString *ProcessString)
94 {
96         // Reset an unused string.
98         ProcessString->Replace(wxT("\\\\"), wxT("\\"), TRUE);
99         ProcessString->Replace(wxT("\\n"), wxT("\n"), TRUE);
100         ProcessString->Replace(wxT("\\;"), wxT(";"), TRUE);
101         ProcessString->Replace(wxT("\\,"), wxT(","), TRUE);
105 void ConvertToHTML(wxString *ProcessString)
108         // Convert string into text that can be used with a 
109         // wxHTMLWindow.
111         ProcessString->Replace(wxT("&"), wxT("&amp;"), TRUE);
112         ProcessString->Replace(wxT("<"), wxT("&lt;"), TRUE);
113         ProcessString->Replace(wxT(">"), wxT("&gt;"), TRUE);
114         ProcessString->Replace(wxT("\n"), wxT("<br>"), TRUE);
118 void DeleteMapDataProcess(int IndexNum, std::map<int, std::string>* MapData){
120         // Delete map data (for map<int,string>).
122         MapData->erase(IndexNum);
123         
126 void DeleteMapDataProcess(int IndexNum, std::map<int, wxString>* MapData){
128         // Delete map data (for map<int,wxString>).
130         MapData->erase(IndexNum);
131         
134 void DeleteMapDataProcess(int IndexNum, std::map<int, int>* MapData){
136         // Delete map data (for map<int,int>).
138         MapData->erase(IndexNum);
139         
142 void DeleteMapDataProcess(int IndexNum, std::map<int, bool>* MapData){
144         // Delete map data (for map<int,bool>).
146         MapData->erase(IndexNum);
147         
150 bool MapDataExists(int *ItemIndex, std::map<int,wxString> *MapPtr){
152         // Check if map data exists (for map<int,wxString>).
153         
154         if (MapPtr->find(*ItemIndex) == MapPtr->end()){
155         
156                 return FALSE;
157         
158         } else {
159         
160                 return TRUE;
161         
162         }
166 bool MapDataExists(int *ItemIndex, std::map<int,int> *MapPtr){
168         // Check if map data exists (for map<int,int>).
170         if (MapPtr->find(*ItemIndex) == MapPtr->end()){
171         
172                 return FALSE;
173         
174         } else {
175         
176                 return TRUE;
177         
178         }
182 wxString OutputText(wxString *TextInput){
183         
184         wxString OutputTextData;
185         wxString OutputLine;
186         int CharSeek = 0;
187         int LineSeek = 0;
188         int MaxLineSeek = 77;
189         
190         for (CharSeek = 0; CharSeek < TextInput->size(); CharSeek++){
191                 
192                 LineSeek++;
193                 
194                 if (LineSeek == MaxLineSeek){
196                         if (TextInput->substr(CharSeek, 1) != "\n"){
197                                 OutputLine += TextInput->substr(CharSeek, 1);
198                         }
199                         OutputLine += "\n";
200                         OutputTextData += OutputLine;
201                         OutputLine = " ";
202                         LineSeek = 0;
203                         MaxLineSeek = 76;
204                         continue;
205                         
206                 }
207                 
208                 OutputLine += TextInput->substr(CharSeek, 1);
209                 
210         }
212         if (OutputLine != " " && OutputLine != " \n"){
213         
214                 OutputTextData += OutputLine;
215                 
216         }
217         
218         return OutputTextData;
219         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy