Skip to content

Commit efc70bd

Browse files
committed
wip - fix string split
1 parent 8ff1bec commit efc70bd

File tree

4 files changed

+19
-63
lines changed

4 files changed

+19
-63
lines changed

src/aws-cpp-sdk-core/include/aws/core/http/URI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ namespace Aws
139139
ss << pathSegments;
140140
Aws::String segments = ss.str();
141141
const auto splitOption = s_preservePathSeparators
142-
? Utils::StringUtils::SplitOptions::PRESERVE_DELIMITERS
142+
? Utils::StringUtils::SplitOptions::INCLUDE_EMPTY_SEGMENTS
143143
: Utils::StringUtils::SplitOptions::NOT_SET;
144144
for (const auto& segment : Aws::Utils::StringUtils::Split(segments, '/', splitOption))
145145
{

src/aws-cpp-sdk-core/include/aws/core/utils/StringUtils.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,13 @@ namespace Aws
7979
*/
8080
NOT_SET,
8181
/**
82-
* Includes empty entries in the vector returned by Split()
82+
* Deprecated use INCLUDE_EMPTY_SEGMENTS instead.
8383
*/
8484
INCLUDE_EMPTY_ENTRIES,
8585
/**
86-
* Include delimeter in vector returned, however removing leading and trailing
87-
* delimiters.
86+
* Include delimeters as empty segments in the split string
8887
*/
89-
PRESERVE_DELIMITERS,
88+
INCLUDE_EMPTY_SEGMENTS,
9089
};
9190

9291
/**
@@ -122,12 +121,11 @@ namespace Aws
122121
static Aws::Vector<Aws::String> Split(const Aws::String& toSplit, char splitOn, size_t numOfTargetParts, SplitOptions option);
123122

124123
/**
125-
* Splits a string on delimeter, keeping the delimeter in the vector returned.
124+
* Splits a string on delimeter, keeping the delimiter in the string as a empty space.
126125
* @param toSplit, the original string to split
127126
* @param splitOn, the delimiter you want to use.
128-
* @param numOfTargetParts, how many target parts you want to get, if it is 0, as many as possible.
129127
*/
130-
static Aws::Vector<Aws::String> SplitWithDelimiters(const Aws::String& toSplit, char splitOn, size_t numOfTargetParts);
128+
static Aws::Vector<Aws::String> SplitWithSpaces(const Aws::String& toSplit, char splitOn);
131129

132130
/**
133131
* Splits a string on new line characters.

src/aws-cpp-sdk-core/source/http/URI.cpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,8 @@ Aws::String URI::GetPath() const
202202

203203
for (auto const& segment : m_pathSegments)
204204
{
205-
if((s_preservePathSeparators && segment == "/"))
206-
{
207-
path.push_back('/');
208-
}
209-
else
210-
{
211-
if (!s_preservePathSeparators)
212-
{
213-
path.push_back('/');
214-
}
215-
path.append(segment);
216-
}
205+
path.push_back('/');
206+
path.append(segment);
217207
}
218208

219209
if (m_pathSegments.empty() || m_pathHasTrailingSlash)
@@ -230,18 +220,7 @@ Aws::String URI::GetURLEncodedPath() const
230220

231221
for (auto const& segment : m_pathSegments)
232222
{
233-
if((s_preservePathSeparators && segment == "/"))
234-
{
235-
ss << "/";
236-
}
237-
else
238-
{
239-
if (!s_preservePathSeparators)
240-
{
241-
ss << "/";
242-
}
243-
ss << StringUtils::URLEncode(segment.c_str());
244-
}
223+
ss << '/' << StringUtils::URLEncode(segment.c_str());
245224
}
246225

247226
if (m_pathSegments.empty() || m_pathHasTrailingSlash)
@@ -261,18 +240,7 @@ Aws::String URI::GetURLEncodedPathRFC3986() const
261240
// (mostly; there is some non-standards legacy support that can be disabled)
262241
for (const auto& segment : m_pathSegments)
263242
{
264-
if((s_preservePathSeparators && segment == "/"))
265-
{
266-
ss << "/";
267-
}
268-
else
269-
{
270-
if (!s_preservePathSeparators)
271-
{
272-
ss << "/";
273-
}
274-
ss << urlEncodeSegment(segment, m_useRfcEncoding);
275-
}
243+
ss << '/' << urlEncodeSegment(segment, m_useRfcEncoding);
276244
}
277245

278246
if (m_pathSegments.empty() || m_pathHasTrailingSlash)

src/aws-cpp-sdk-core/source/utils/StringUtils.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ Aws::Vector<Aws::String> StringUtils::Split(const Aws::String& toSplit, char spl
9090

9191
Aws::Vector<Aws::String> StringUtils::Split(const Aws::String& toSplit, char splitOn, size_t numOfTargetParts, SplitOptions option)
9292
{
93-
if (option == SplitOptions::PRESERVE_DELIMITERS)
93+
if (option == SplitOptions::INCLUDE_EMPTY_SEGMENTS)
9494
{
95-
return StringUtils::SplitWithDelimiters(toSplit, splitOn, numOfTargetParts);
95+
return StringUtils::SplitWithSpaces(toSplit, splitOn);
9696
}
9797

9898
Aws::Vector<Aws::String> returnValues;
@@ -133,25 +133,15 @@ Aws::Vector<Aws::String> StringUtils::Split(const Aws::String& toSplit, char spl
133133
return returnValues;
134134
}
135135

136-
Aws::Vector<Aws::String> StringUtils::SplitWithDelimiters(const Aws::String& toSplit, char splitOn, size_t numOfTargetParts)
136+
Aws::Vector<Aws::String> StringUtils::SplitWithSpaces(const Aws::String& toSplit, char splitOn)
137137
{
138-
Aws::Vector<Aws::String> returnValues;
139-
size_t start = 0;
140-
size_t found = toSplit.find_first_of(splitOn, start);
141-
142-
while (returnValues.size() < numOfTargetParts && found != std::string::npos) {
143-
if (found > start) {
144-
returnValues.push_back(toSplit.substr(start, found - start));
145-
}
146-
returnValues.push_back(toSplit.substr(found, 1));
147-
start = found + 1;
148-
found = toSplit.find_first_of(splitOn, start);
138+
size_t pos = 0;
139+
String split{toSplit};
140+
Vector<String> returnValues;
141+
while ((pos = split.find(splitOn)) != std::string::npos) {
142+
returnValues.emplace_back(split.substr(0, pos));
143+
split.erase(0, pos + 1);
149144
}
150-
151-
if (start < toSplit.length()) {
152-
returnValues.push_back(toSplit.substr(start));
153-
}
154-
155145
return returnValues;
156146
}
157147

0 commit comments

Comments
 (0)