-
Notifications
You must be signed in to change notification settings - Fork 15
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
#989: Trim script class and import script options #465
Merged
tomuben
merged 5 commits into
master
from
bug/989_trim_scriptclass_and_import_script_options
Oct 22, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
453577a
#989: Trim script class and import script options
tomuben f29d6c1
Use std::unique_ptr for storing temp script code in JavaVMTest::run i…
tomuben 6ff5329
Fixed javavm_test.cc
tomuben 65e8934
Got rid of ::strdup() in JavaVMTest::run.
tomuben f552241
Findings from review
tomuben 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
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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "base/javacontainer/script_options/string_ops.h" |
41 changes: 41 additions & 0 deletions
41
exaudfclient/base/javacontainer/script_options/string_ops.h
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef SCRIPTOPTIONLINEPARSERSTRINGOPS_H | ||
#define SCRIPTOPTIONLINEPARSERSTRINGOPS_H 1 | ||
|
||
#include <string> | ||
#include <algorithm> | ||
|
||
|
||
|
||
namespace SWIGVMContainers { | ||
|
||
namespace JavaScriptOptions { | ||
|
||
namespace StringOps { | ||
|
||
//Following code is based on https://stackoverflow.com/a/217605 | ||
|
||
inline void ltrim(std::string &s) { | ||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { | ||
return !std::isspace(ch); | ||
})); | ||
} | ||
|
||
inline void rtrim(std::string &s) { | ||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { | ||
return !std::isspace(ch); | ||
}).base(), s.end()); | ||
} | ||
|
||
inline void trim(std::string &s) { | ||
ltrim(s); | ||
rtrim(s); | ||
} | ||
|
||
} //namespace StringOps | ||
|
||
|
||
} //namespace JavaScriptOptions | ||
|
||
} //namespace SWIGVMContainers | ||
|
||
#endif //SCRIPTOPTIONLINEPARSERSTRINGOPS_H |
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
27 changes: 27 additions & 0 deletions
27
exaudfclient/base/javacontainer/script_options/test/string_ops_tests.cc
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
#include "include/gtest/gtest.h" | ||
#include "gmock/gmock.h" | ||
#include "base/javacontainer/script_options/string_ops.h" | ||
|
||
using namespace SWIGVMContainers::JavaScriptOptions; | ||
|
||
|
||
|
||
|
||
TEST(StringOpsTest, trim) { | ||
std::string sample = " \tHello World \t"; | ||
StringOps::trim(sample); | ||
EXPECT_EQ(sample, "Hello World"); | ||
} | ||
|
||
TEST(StringOpsTest, trimWithNoneASCII) { | ||
/* | ||
Test that trim works correctly with None-ASCII characters | ||
\xa0's bit sequence is '1010 0000', while space bit sequence '0010 0000'. | ||
If StringOps::trim() would not work correctly with characters where MSB is set, it would interpret \xa0 as space. | ||
*/ | ||
std::string sample = " \t\xa0Hello World\xa0 \t"; | ||
StringOps::trim(sample); | ||
EXPECT_EQ(sample, "\xa0Hello World\xa0"); | ||
} | ||
|
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
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
Oops, something went wrong.
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.
does it make sense also to add a test with a quoted import script, because it is legal