24 #include <wx/tokenzr.h>
25 #include <wx/string.h>
28 #include "model/position_parser.h"
29 #include "model/navutil_base.h"
31 PositionParser::PositionParser(
const wxString& src) {
33 if (FindSeparator(src)) {
34 latitude = fromDMM(latitudeString);
35 longitude = fromDMM(longitudeString);
36 if ((latitude != 0.0) && (longitude != 0.0)) parsedOk =
true;
40 bool PositionParser::FindSeparator(
const wxString& src) {
42 wxString posPartOfSeparator = _T(
"");
50 int re_compile_flags = wxRE_ICASE;
51 #ifdef wxHAS_REGEX_ADVANCED
52 re_compile_flags |= wxRE_ADVANCED;
56 _T(
"<[a-z,A-Z]*\\s*[a-z,A-Z]*=\"([0-9,.]*)\"\\s*[a-z,A-Z]*=\"([-,0-9,.]*)\"\\s*/*>" ),
59 if (regex.IsValid()) {
60 if (regex.Matches(src)) {
61 int n = regex.GetMatchCount();
62 latitudeString = regex.GetMatch(src, 1);
63 longitudeString = regex.GetMatch(src, 2);
64 latitudeString.Trim(
true);
65 latitudeString.Trim(
false);
66 longitudeString.Trim(
true);
67 longitudeString.Trim(
false);
75 wxStringTokenizer tk1(src, separator);
76 if (tk1.CountTokens() == 2) {
77 latitudeString = tk1.GetNextToken();
78 latitudeString.Trim(
true);
79 latitudeString.Trim(
false);
80 longitudeString = tk1.GetNextToken();
81 longitudeString.Trim(
true);
82 longitudeString.Trim(
false);
88 wxStringTokenizer tk2(src, separator);
89 if (tk2.CountTokens() == 2) {
90 latitudeString = tk2.GetNextToken();
91 latitudeString.Trim(
true);
92 latitudeString.Trim(
false);
93 longitudeString = tk2.GetNextToken();
94 longitudeString.Trim(
true);
95 longitudeString.Trim(
false);
101 wxStringTokenizer tk3(src, separator);
102 if (tk3.CountTokens() == 2) {
103 latitudeString = tk3.GetNextToken();
104 latitudeString.Trim(
true);
105 latitudeString.Trim(
false);
106 longitudeString = tk3.GetNextToken();
107 longitudeString.Trim(
true);
108 longitudeString.Trim(
false);
113 separator = _T(
"\t");
114 wxStringTokenizer tk4(src, separator);
115 if (tk4.CountTokens() == 2) {
116 latitudeString = tk4.GetNextToken();
117 latitudeString.Trim(
true);
118 latitudeString.Trim(
false);
119 longitudeString = tk4.GetNextToken();
120 longitudeString.Trim(
true);
121 longitudeString.Trim(
false);
126 separator = _T(
"\n");
127 wxStringTokenizer tk5(src, separator);
128 if (tk5.CountTokens() == 2) {
129 latitudeString = tk5.GetNextToken();
130 latitudeString.Trim(
true);
131 latitudeString.Trim(
false);
132 longitudeString = tk5.GetNextToken();
133 longitudeString.Trim(
true);
134 longitudeString.Trim(
false);
140 posPartOfSeparator = _T(
"N");
141 wxStringTokenizer tk6(src, separator);
142 if (tk6.CountTokens() == 2) {
143 latitudeString = tk6.GetNextToken() << posPartOfSeparator;
144 latitudeString.Trim(
true);
145 latitudeString.Trim(
false);
146 longitudeString = tk6.GetNextToken();
147 longitudeString.Trim(
true);
148 longitudeString.Trim(
false);
154 posPartOfSeparator = _T(
"S");
155 wxStringTokenizer tk7(src, separator);
156 if (tk7.CountTokens() == 2) {
157 latitudeString = tk7.GetNextToken() << posPartOfSeparator;
158 latitudeString.Trim(
true);
159 latitudeString.Trim(
false);
160 longitudeString = tk7.GetNextToken();
161 longitudeString.Trim(
true);
162 longitudeString.Trim(
false);