aboutsummaryrefslogtreecommitdiffstats
path: root/util/folder/pathsplit.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/folder/pathsplit.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/folder/pathsplit.cpp')
-rw-r--r--util/folder/pathsplit.cpp210
1 files changed, 105 insertions, 105 deletions
diff --git a/util/folder/pathsplit.cpp b/util/folder/pathsplit.cpp
index 81d439a727..15d5b8e616 100644
--- a/util/folder/pathsplit.cpp
+++ b/util/folder/pathsplit.cpp
@@ -1,138 +1,138 @@
-#include "pathsplit.h"
-
+#include "pathsplit.h"
+
#include "dirut.h"
-#include <util/stream/output.h>
-#include <util/generic/yexception.h>
-
-template <class T>
-static inline size_t ToReserve(const T& t) {
- size_t ret = t.size() + 5;
-
- for (auto it = t.begin(); it != t.end(); ++it) {
- ret += it->size();
- }
-
- return ret;
-}
-
+#include <util/stream/output.h>
+#include <util/generic/yexception.h>
+
+template <class T>
+static inline size_t ToReserve(const T& t) {
+ size_t ret = t.size() + 5;
+
+ for (auto it = t.begin(); it != t.end(); ++it) {
+ ret += it->size();
+ }
+
+ return ret;
+}
+
void TPathSplitTraitsUnix::DoParseFirstPart(const TStringBuf part) {
if (part == TStringBuf(".")) {
push_back(TStringBuf("."));
-
- return;
- }
-
- if (IsAbsolutePath(part)) {
+
+ return;
+ }
+
+ if (IsAbsolutePath(part)) {
IsAbsolute = true;
- }
-
- DoParsePart(part);
-}
-
+ }
+
+ DoParsePart(part);
+}
+
void TPathSplitTraitsUnix::DoParsePart(const TStringBuf part0) {
DoAppendHint(part0.size() / 8);
-
- TStringBuf next(part0);
- TStringBuf part;
-
+
+ TStringBuf next(part0);
+ TStringBuf part;
+
while (TStringBuf(next).TrySplit('/', part, next)) {
- AppendComponent(part);
- }
-
- AppendComponent(next);
-}
-
+ AppendComponent(part);
+ }
+
+ AppendComponent(next);
+}
+
void TPathSplitTraitsWindows::DoParseFirstPart(const TStringBuf part0) {
- TStringBuf part(part0);
-
+ TStringBuf part(part0);
+
if (part == TStringBuf(".")) {
push_back(TStringBuf("."));
-
- return;
- }
-
- if (IsAbsolutePath(part)) {
- IsAbsolute = true;
-
+
+ return;
+ }
+
+ if (IsAbsolutePath(part)) {
+ IsAbsolute = true;
+
if (part.size() > 1 && part[1] == ':') {
- Drive = part.SubStr(0, 2);
- part = part.SubStr(2);
- }
- }
-
- DoParsePart(part);
-}
-
+ Drive = part.SubStr(0, 2);
+ part = part.SubStr(2);
+ }
+ }
+
+ DoParsePart(part);
+}
+
void TPathSplitTraitsWindows::DoParsePart(const TStringBuf part0) {
DoAppendHint(part0.size() / 8);
-
- size_t pos = 0;
- TStringBuf part(part0);
-
+
+ size_t pos = 0;
+ TStringBuf part(part0);
+
while (pos < part.size()) {
while (pos < part.size() && this->IsPathSep(part[pos])) {
- ++pos;
- }
-
+ ++pos;
+ }
+
const char* begin = part.data() + pos;
-
+
while (pos < part.size() && !this->IsPathSep(part[pos])) {
- ++pos;
- }
-
+ ++pos;
+ }
+
AppendComponent(TStringBuf(begin, part.data() + pos));
- }
-}
-
+ }
+}
+
TString TPathSplitStore::DoReconstruct(const TStringBuf slash) const {
TString r;
-
- r.reserve(ToReserve(*this));
-
- if (IsAbsolute) {
- r.AppendNoAlias(Drive);
- r.AppendNoAlias(slash);
- }
-
- for (auto i = begin(); i != end(); ++i) {
- if (i != begin()) {
- r.AppendNoAlias(slash);
- }
-
- r.AppendNoAlias(*i);
- }
-
- return r;
-}
-
+
+ r.reserve(ToReserve(*this));
+
+ if (IsAbsolute) {
+ r.AppendNoAlias(Drive);
+ r.AppendNoAlias(slash);
+ }
+
+ for (auto i = begin(); i != end(); ++i) {
+ if (i != begin()) {
+ r.AppendNoAlias(slash);
+ }
+
+ r.AppendNoAlias(*i);
+ }
+
+ return r;
+}
+
void TPathSplitStore::AppendComponent(const TStringBuf comp) {
if (!comp || comp == TStringBuf(".")) {
- ; // ignore
+ ; // ignore
} else if (comp == TStringBuf("..") && !empty() && back() != TStringBuf("..")) {
- pop_back();
- } else {
- // push back first .. also
- push_back(comp);
- }
-}
-
-TStringBuf TPathSplitStore::Extension() const {
+ pop_back();
+ } else {
+ // push back first .. also
+ push_back(comp);
+ }
+}
+
+TStringBuf TPathSplitStore::Extension() const {
return size() > 0 ? CutExtension(back()) : TStringBuf();
}
-template <>
+template <>
void Out<TPathSplit>(IOutputStream& o, const TPathSplit& ps) {
- o << ps.Reconstruct();
-}
-
+ o << ps.Reconstruct();
+}
+
TString JoinPaths(const TPathSplit& p1, const TPathSplit& p2) {
- if (p2.IsAbsolute) {
- ythrow yexception() << "can not join " << p1 << " and " << p2;
- }
-
- return TPathSplit(p1).AppendMany(p2.begin(), p2.end()).Reconstruct();
-}
+ if (p2.IsAbsolute) {
+ ythrow yexception() << "can not join " << p1 << " and " << p2;
+ }
+
+ return TPathSplit(p1).AppendMany(p2.begin(), p2.end()).Reconstruct();
+}
TStringBuf CutExtension(const TStringBuf fileName) {
if (fileName.empty()) {