This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
[Bug 14861] LCB: Add "reverse _" syntax for sequence types (String, List, Data) #5328
Merged
Conversation
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 is useful when `MCAutoValueRefBase`-derived managed pointers are used in the implementation of libfoundation. `t_string->chars` is a lot clearer than `(*t_string)->chars`.
Add a private template that provides in-place reverse for an array. The algorithm works from the middle of the array, working outwards and swapping elements between the front and the back. It can only be used for types that are suitable for use with `std::swap()`; either trivially copyable, or with an implementation of `T::swap(T& other)`.
Add a function that reverses a mutable list instance in place.
Add a function that reverses the order of bytes in a mutable `MCData` instance in-place.
Strings cannot be reversed in-place in the general case. There is no upper limit on the number of codeunits in a grapheme, which means that a temporary buffer of at the same length of the string is required for general correctness. This patch adds a "reversed copy" function which performs a deep copy of the source string, and then constructs the reversed form in the copy by re-reading from the source string via a grapheme break iterator. In practice, the "trivial" flag is not getting set for trivial strings, so all strings that use UTF-16 internal representatino go through the slow grapheme break iterator path.
Add the ability to reverse a binary string in an LCB program with a new `reverse tData` statement.
Add the ability to reverse the order of bytes in a list with the `reverse tList` statement.
Add a new function to reverse an LCB string in-place using the `reverse tString` statement.
Now that there is a `reverse` statement, provide an alternative example of looping over the contents of a string.
@peter-b, thanks for your PR! By analyzing the history of the files in this pull request, we identified @livecodeian, @runrevmark and @livecodesebastien to be potential reviewers. |
The newly-introduced `MCInplaceReverse()` function requires `<utility>` to get `std::swap()`.
livecodeali
reviewed
Apr 5, 2017
* unichar_t codeunits items per grapheme. In this case, we | ||
* reverse by iterating over the contents of the original | ||
* string, copying the graphemes into the new string. */ | ||
MCStringRef t_original = __MCStringIsIndirect(self) ? self->string : self; |
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.
Please avoid using the ternary conditional operator
@livecode-vulcan review ok de86d30 |
💙 review by @livecodeali ok de86d30 |
livecode-vulcan
added a commit
that referenced
this pull request
Apr 5, 2017
[Bug 14861] LCB: Add "reverse _" syntax for sequence types (String, List, Data) This patch adds in-place `reverse _` syntax to LCB for sequence types (`List`, `String` and `Data`). ``` variable tList put [1, 2, 3] into tList reverse tList expect that tList is [3, 2, 1] ``` There are several components: - An `MCInplaceReverse()` template function for libfoundation internal use that supports any type that has a `swap()` operation - In-place `MCProperListReverse()` and `MCDataReverse()` functions which operate on mutable values - `MCStringCopyReverse()`, which creates a copy of a string with the order of its _graphemes_ reversed - LCB syntax definitions, documentation, examples and unit tests
😎 test success de86d30
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 patch adds in-place
reverse _
syntax to LCB for sequence types (List
,String
andData
).There are several components:
MCInplaceReverse()
template function for libfoundation internal use that supports any type that has aswap()
operationMCProperListReverse()
andMCDataReverse()
functions which operate on mutable valuesMCStringCopyReverse()
, which creates a copy of a string with the order of its graphemes reversed