aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/reverse.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/string/reverse.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/string/reverse.cpp')
-rw-r--r--util/string/reverse.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/util/string/reverse.cpp b/util/string/reverse.cpp
new file mode 100644
index 0000000000..167cd11f49
--- /dev/null
+++ b/util/string/reverse.cpp
@@ -0,0 +1,33 @@
+#include "reverse.h"
+
+#include <util/generic/string.h>
+#include <util/generic/vector.h>
+#include <util/charset/wide_specific.h>
+
+#include <algorithm>
+
+void ReverseInPlace(TString& string) {
+ auto* begin = string.begin();
+ std::reverse(begin, begin + string.size());
+}
+
+void ReverseInPlace(TUtf16String& string) {
+ auto* begin = string.begin();
+ const auto len = string.size();
+ auto* end = begin + string.size();
+
+ TVector<wchar16> buffer(len);
+ wchar16* rbegin = buffer.data() + len;
+ for (wchar16* p = begin; p < end;) {
+ const size_t symbolSize = W16SymbolSize(p, end);
+ rbegin -= symbolSize;
+ std::copy(p, p + symbolSize, rbegin);
+ p += symbolSize;
+ }
+ std::copy(buffer.begin(), buffer.end(), begin);
+}
+
+void ReverseInPlace(TUtf32String& string) {
+ auto* begin = string.begin();
+ std::reverse(begin, begin + string.size());
+}