add slice and shorten_json_string#11598
Merged
maloel merged 5 commits intorealsenseai:ddsfrom Mar 22, 2023
Merged
Conversation
OhadMeir
reviewed
Mar 22, 2023
| // find an opening | ||
| slice::const_iterator it = outside.begin() + 1; // opening {, separating comma, etc. | ||
| bool in_quote = false; | ||
| while( it < outside.end() && ( in_quote || *it != '[' && *it != '{' ) ) |
Contributor
There was a problem hiding this comment.
It is better to move *it != '[' && *it != '{' to a separate function is_opening, the meaning will be clearer.
For the very least surround with parenthesis, don't count on operator && precedence over ||.
Contributor
Author
There was a problem hiding this comment.
I don't like parens that aren't needed generally... I'll try to add is_opening
OhadMeir
reviewed
Mar 22, 2023
| const_iterator _begin, _end; | ||
|
|
||
| public: | ||
| slice( const_iterator begin, const_iterator end ) |
Contributor
There was a problem hiding this comment.
It is better to leave a blank line between functions.
Fix if you'll have some other changes to this file.
OhadMeir
reviewed
Mar 22, 2023
| return ellipsis( slice(), str ); // impossible: "{ ... }" is the minimum | ||
|
|
||
| // Try to find an inside block that can be taken out | ||
| ellipsis final; |
Contributor
There was a problem hiding this comment.
final can serve as a C++ keyword in other context, better to use other name. result?
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a utility function I used in one PoC that thought would be useful to have in rsutils, especially now that we're making a bigger use of json.
It also adds what I consider a very useful utility
slice, similar to astring_view. For example, I wanted to refer to the json string insideflexible_msgbut it's not null-teminated. The easy way is by using a slice:LOG_DEBUG( "publishing metadata: " << shorten_json_string( slice( md.custom_data< char const >(), md._data.size() )));Anyway I didn't want to lose this so decided to PR.