-
-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revise SplitString #1508
Merged
Merged
Revise SplitString #1508
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,62 @@ | ||
#include "SplitString.h" | ||
|
||
int splitString(String &what, int delim, Vector<long> &splits) | ||
{ | ||
what.trim(); | ||
splits.removeAllElements(); | ||
const char *chars = what.buffer; | ||
int splitCount = 0; //1; | ||
for (int i = 0; i < what.length(); i++) | ||
{ | ||
if (chars[i] == delim) splitCount++; | ||
} | ||
if (splitCount == 0) | ||
{ | ||
splits.addElement(atol(what.buffer)); | ||
return 1; | ||
} | ||
|
||
int pieceCount = splitCount + 1; | ||
/* $Id: WMemory.cpp 1156 2011-06-07 04:01:16Z bhagman $ | ||
|| | ||
|| @author Hernando Barragan <[email protected]> | ||
|| @url http://wiring.org.co/ | ||
|| @contribution Brett Hagman <[email protected]> | ||
|| @contribution Alexander Brevig <[email protected]> | ||
|| | ||
|| @license Please see cores/Common/License.txt. | ||
|| | ||
*/ | ||
|
||
int splitIndex = 0; | ||
int startIndex = 0; | ||
for (int i = 0; i < what.length(); i++) | ||
{ | ||
if (chars[i] == delim) | ||
{ | ||
splits.addElement(atol(what.substring(startIndex, i).buffer)); | ||
splitIndex++; | ||
startIndex = i + 1; | ||
} | ||
} | ||
splits.addElement(atol(what.substring(startIndex, what.length()).buffer)); | ||
|
||
return pieceCount; | ||
} | ||
#include "SplitString.h" | ||
|
||
int splitString(String &what, int delim, Vector<int> &splits) | ||
int splitString(String &what, char delim, Vector<int> &splits) | ||
{ | ||
what.trim(); | ||
splits.removeAllElements(); | ||
const char *chars = what.buffer; | ||
int splitCount = 0; //1; | ||
for (int i = 0; i < what.length(); i++) | ||
const char *chars = what.c_str(); | ||
unsigned splitCount = 0; | ||
for (unsigned i = 0; i < what.length(); i++) | ||
{ | ||
if (chars[i] == delim) splitCount++; | ||
} | ||
if (splitCount == 0) | ||
{ | ||
splits.addElement(atoi(what.buffer)); | ||
splits.addElement(what.toInt()); | ||
return(1); | ||
} | ||
|
||
int pieceCount = splitCount + 1; | ||
|
||
int splitIndex = 0; | ||
int startIndex = 0; | ||
for (int i = 0; i < what.length(); i++) | ||
for (unsigned i = 0; i < what.length(); i++) | ||
{ | ||
if (chars[i] == delim) | ||
if(what[i] == delim) | ||
{ | ||
splits.addElement(atoi(what.substring(startIndex, i).buffer)); | ||
splitIndex++; | ||
splits.addElement(what.substring(startIndex, i).toInt()); | ||
startIndex = i + 1; | ||
} | ||
} | ||
splits.addElement(atoi(what.substring(startIndex, what.length()).buffer)); | ||
splits.addElement(what.substring(startIndex).toInt()); | ||
|
||
return pieceCount; | ||
return splits.count(); | ||
} | ||
|
||
int splitString(String &what, int delim, Vector<String> &splits) | ||
int splitString(String &what, char delim, Vector<String> &splits) | ||
{ | ||
what.trim(); | ||
splits.removeAllElements(); | ||
const char *chars = what.buffer; | ||
int splitCount = 0; | ||
const char *chars = what.c_str(); | ||
|
||
int splitIndex = 0; | ||
int startIndex = 0; | ||
for (int i = 0; i < what.length(); i++) | ||
for (unsigned i = 0; i < what.length(); i++) | ||
{ | ||
if (chars[i] == delim) | ||
{ | ||
splits.addElement(what.substring(startIndex, i).buffer); | ||
splitIndex++; | ||
splits.addElement(what.substring(startIndex, i)); | ||
startIndex = i + 1; | ||
splitCount++; | ||
} | ||
} | ||
splits.addElement(what.substring(startIndex, what.length()).buffer); | ||
|
||
return (splitCount + 1); | ||
splits.addElement(what.substring(startIndex)); | ||
|
||
return splits.count(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,6 @@ | |
|| @contribution Brett Hagman <[email protected]> | ||
|| @contribution Alexander Brevig <[email protected]> | ||
|| | ||
|| @description | ||
|| | Implementation of c++ new/delete operators. | ||
|| | | ||
|| | Wiring Common API | ||
|| # | ||
|| | ||
|| @license Please see cores/Common/License.txt. | ||
|| | ||
*/ | ||
|
@@ -22,8 +16,24 @@ | |
#include "WString.h" | ||
#include "WiringFrameworkDependencies.h" | ||
|
||
int splitString(String &what, int delim, Vector<long> &splits); | ||
int splitString(String &what, int delim, Vector<int> &splits); | ||
int splitString(String &what, int delim, Vector<String> &splits); | ||
/** @brief split a delimited string list of integers into an array | ||
* @param what | ||
* @param delim | ||
* @param splits | ||
* @retval number of items returned in splits (same as splits.count()) | ||
* @note leading/trailing whitespace is removed from 'what' before parsing | ||
* example: " 1,2,3,4,5" returns [1, 2, 3, 4, 5] | ||
*/ | ||
int splitString(String &what, char delim, Vector<int> &splits); | ||
|
||
/** @brief split a delimited string list into an array | ||
* @param what | ||
* @param delim | ||
* @param splits | ||
* @retval number of items returned in splits (same as splits.count()) | ||
* @note leading/trailing whitespace is removed from 'what' before parsing | ||
* example: " a,b,c,d,e" returns ["a", "b", "c", "d", "e"] | ||
*/ | ||
int splitString(String &what, char delim, Vector<String> &splits); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WMemory.cpp
->SplitString.cpp
.