aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorstepych <stepych@yandex-team.ru>2022-02-10 16:50:51 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:51 +0300
commite43b253871ab6f365f22f9a139a082da542d32f7 (patch)
treeff1cbc0a584180ffb1b3cb801e24c53df865044c /library/cpp
parent516d85cb3e198d4461ddfe35c5f05928948a5c40 (diff)
downloadydb-e43b253871ab6f365f22f9a139a082da542d32f7.tar.gz
Restoring authorship annotation for <stepych@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/uri/common.h26
-rw-r--r--library/cpp/uri/qargs.cpp158
-rw-r--r--library/cpp/uri/qargs.h22
-rw-r--r--library/cpp/uri/uri_ut.cpp46
-rw-r--r--library/cpp/uri/ya.make2
5 files changed, 127 insertions, 127 deletions
diff --git a/library/cpp/uri/common.h b/library/cpp/uri/common.h
index 8025357763..8008bcca3a 100644
--- a/library/cpp/uri/common.h
+++ b/library/cpp/uri/common.h
@@ -442,12 +442,12 @@ namespace NUri {
#define FEATURE_NAME(f) _BitFeature##f
#define FEATURE_FLAG_NAME(f) Feature##f
-#define FEATURE_FLAG(f) FEATURE_FLAG_NAME(f) = 1UL << FEATURE_NAME(f)
-
+#define FEATURE_FLAG(f) FEATURE_FLAG_NAME(f) = 1UL << FEATURE_NAME(f)
+
struct TQueryArg {
TStringBuf Name;
TStringBuf Value;
-
+
private:
enum EBit {
FEATURE_NAME(Filter),
@@ -456,7 +456,7 @@ namespace NUri {
FEATURE_NAME(RewriteDirty),
_FeatureMAX
};
-
+
public:
enum EPublic : ui32 {
FeatureMAX = _FeatureMAX,
@@ -465,25 +465,25 @@ namespace NUri {
FEATURE_FLAG(RemoveEmptyQuery),
FEATURE_FLAG(RewriteDirty),
};
-
+
enum EProcessed {
// OK and clean.
ProcessedOK = 0,
-
+
// OK, but query stored in internal buffer and TUri::Rewrite() is required.
ProcessedDirty = 1,
-
+
ProcessedMalformed = 2,
ProcessedTooMany = 3,
};
};
-
+
typedef bool (*TQueryArgFilter)(const TQueryArg& arg, void* filterData);
-
-#undef FEATURE_NAME
-#undef FEATURE_FLAG_NAME
-#undef FEATURE_FLAG
-
+
+#undef FEATURE_NAME
+#undef FEATURE_FLAG_NAME
+#undef FEATURE_FLAG
+
const char* FieldToString(const TField::EField& t);
const char* ParsedStateToString(const TState::EParsed& t);
const char* SchemeKindToString(const TScheme::EKind& t);
diff --git a/library/cpp/uri/qargs.cpp b/library/cpp/uri/qargs.cpp
index 23058f8102..0873ca8781 100644
--- a/library/cpp/uri/qargs.cpp
+++ b/library/cpp/uri/qargs.cpp
@@ -1,21 +1,21 @@
-#include "qargs.h"
-#include <string>
-
-namespace NUri {
+#include "qargs.h"
+#include <string>
+
+namespace NUri {
namespace NOnStackArgsList {
struct TQArgNode {
TQArgNode* Prev;
TQArgNode* Next;
-
+
TStringBuf Name;
TStringBuf Value;
TStringBuf All;
};
-
+
TQArgNode MakeArg(TQArgNode* prev) {
return {prev, 0, {}, {}, {}};
}
-
+
const char* SkipDelimiter(const char* str, const char* end) {
while (str != end)
if (*str == '&')
@@ -24,41 +24,41 @@ namespace NUri {
break;
return str;
}
-
+
/// return next pos or 0 if error
const char* ExtractArgData(const char* pos, const char* end, TQArgNode* arg) {
const char* nameStart = pos;
- const char* nextArg = strchr(pos, '&');
- const char* valueStart = strchr(pos, '=');
- if (valueStart && nextArg && valueStart < nextArg) // a=1& or a=&
- {
- arg->Name = TStringBuf(nameStart, valueStart - nameStart);
- arg->Value = TStringBuf(valueStart + 1, nextArg - valueStart - 1);
- arg->All = TStringBuf(nameStart, nextArg - nameStart);
- return nextArg;
- } else if (valueStart && nextArg && valueStart > nextArg) // a&b=2
- {
- arg->Name = TStringBuf(nameStart, nextArg - nameStart);
- arg->All = arg->Name;
- return nextArg;
- } else if (valueStart && !nextArg) // a=1 or a=
- {
- arg->Name = TStringBuf(nameStart, valueStart - nameStart);
- arg->Value = TStringBuf(valueStart + 1, end - valueStart - 1);
- arg->All = TStringBuf(nameStart, end - nameStart);
- return end;
- } else if (!valueStart && nextArg) // a&b
- {
- arg->Name = TStringBuf(nameStart, nextArg - nameStart);
- arg->All = arg->Name;
- return nextArg;
- } else { // a
- arg->Name = TStringBuf(nameStart, end - nameStart);
- arg->All = arg->Name;
- return end;
- }
+ const char* nextArg = strchr(pos, '&');
+ const char* valueStart = strchr(pos, '=');
+ if (valueStart && nextArg && valueStart < nextArg) // a=1& or a=&
+ {
+ arg->Name = TStringBuf(nameStart, valueStart - nameStart);
+ arg->Value = TStringBuf(valueStart + 1, nextArg - valueStart - 1);
+ arg->All = TStringBuf(nameStart, nextArg - nameStart);
+ return nextArg;
+ } else if (valueStart && nextArg && valueStart > nextArg) // a&b=2
+ {
+ arg->Name = TStringBuf(nameStart, nextArg - nameStart);
+ arg->All = arg->Name;
+ return nextArg;
+ } else if (valueStart && !nextArg) // a=1 or a=
+ {
+ arg->Name = TStringBuf(nameStart, valueStart - nameStart);
+ arg->Value = TStringBuf(valueStart + 1, end - valueStart - 1);
+ arg->All = TStringBuf(nameStart, end - nameStart);
+ return end;
+ } else if (!valueStart && nextArg) // a&b
+ {
+ arg->Name = TStringBuf(nameStart, nextArg - nameStart);
+ arg->All = arg->Name;
+ return nextArg;
+ } else { // a
+ arg->Name = TStringBuf(nameStart, end - nameStart);
+ arg->All = arg->Name;
+ return end;
+ }
}
-
+
// arg can be null
TQArgNode* GetHead(TQArgNode* arg) {
TQArgNode* prev = arg;
@@ -68,7 +68,7 @@ namespace NUri {
}
return arg;
}
-
+
// arg can be null
TQArgNode* GetLast(TQArgNode* arg) {
TQArgNode* next = arg;
@@ -78,30 +78,30 @@ namespace NUri {
}
return arg;
}
-
+
int CompareName(const TQArgNode* l, const TQArgNode* r) {
return l->Name.compare(r->Name);
}
-
+
TQArgNode* Move(TQArgNode* before, TQArgNode* node) {
TQArgNode* tn = node->Next;
TQArgNode* tp = node->Prev;
-
+
node->Prev = before->Prev;
if (node->Prev)
node->Prev->Next = node;
-
+
node->Next = before;
before->Prev = node;
-
+
if (tn)
tn->Prev = tp;
if (tp)
tp->Next = tn;
-
+
return node;
}
-
+
// return new head
TQArgNode* QSortByName(TQArgNode* iter, TQArgNode* last) {
if (iter == last)
@@ -123,32 +123,32 @@ namespace NUri {
case -1:
head = head ? Move(head, iter) : Move(pivot, iter);
break;
-
+
case 0:
pivot = Move(pivot, iter);
break;
-
+
case 1:
tail = iter;
break;
}
-
+
if (iter == last)
break;
iter = next;
}
-
+
if (head)
head = QSortByName(head, pivot->Prev);
if (tail)
QSortByName(tailPartitionStart->Next, tail);
return head ? head : pivot;
}
- }
- }
-
+ }
+ }
+
using namespace NOnStackArgsList;
-
+
class TQueryArgProcessing::Pipeline {
public:
Pipeline(TQueryArgProcessing& parent, TUri& subject)
@@ -158,26 +158,26 @@ namespace NUri {
, IsDirty(false)
{
}
-
+
TQueryArg::EProcessed Process() {
const TStringBuf& query = Subject.GetField(NUri::TField::FieldQuery);
if (query.empty())
return ProcessEmpty();
-
+
const char* start = query.data();
return Parse(start, start + query.length(), 0);
}
-
+
TQueryArg::EProcessed ProcessEmpty() {
if (Parent.Flags & TQueryArg::FeatureRemoveEmptyQuery)
Subject.FldClr(NUri::TField::FieldQuery);
-
+
return TQueryArg::ProcessedOK;
}
-
+
TQueryArg::EProcessed Parse(const char* str, const char* end, TQArgNode* prev) {
str = SkipDelimiter(str, end);
-
+
if (str == end) {
TQArgNode* head = GetHead(prev);
TQArgNode* last = GetLast(prev);
@@ -187,16 +187,16 @@ namespace NUri {
const char* next = ExtractArgData(str, end, &current);
if (!next)
return TQueryArg::ProcessedMalformed;
-
+
TQArgNode* tail = ApplyFilter(prev, &current);
-
+
if (++ArgsCount > MaxCount)
return TQueryArg::ProcessedTooMany;
-
+
return Parse(next, end, tail);
}
}
-
+
TQArgNode* ApplyFilter(TQArgNode* prev, TQArgNode* current) {
if (Parent.Flags & TQueryArg::FeatureFilter) {
TQueryArg arg = {current->Name, current->Value};
@@ -209,25 +209,25 @@ namespace NUri {
if (prev)
prev->Next = current;
return current;
- }
-
+ }
+
TQueryArg::EProcessed FinalizeParsing(TQArgNode* head, TQArgNode* last) {
if (Parent.Flags & TQueryArg::FeatureSortByName) {
head = QSortByName(head, last);
IsDirty = true;
}
-
+
if (!IsDirty)
return TQueryArg::ProcessedOK;
-
+
bool dirty = Render(head);
-
+
bool rewrite = Parent.Flags & TQueryArg::FeatureRewriteDirty;
if (dirty && rewrite)
Subject.Rewrite();
return (!dirty || rewrite) ? TQueryArg::ProcessedOK : TQueryArg::ProcessedDirty;
}
-
+
bool Render(TQArgNode* head) {
std::string& result = Parent.Buffer;
result.clear();
@@ -238,42 +238,42 @@ namespace NUri {
first = false;
else
result.append("&");
-
+
result.append(head->All);
head = head->Next;
}
-
+
if (result.empty())
return RenderEmpty();
else
return Subject.FldMemSet(NUri::TField::FieldQuery, result);
}
-
+
bool RenderEmpty() {
if (Parent.Flags & TQueryArg::FeatureRemoveEmptyQuery)
Subject.FldClr(NUri::TField::FieldQuery);
return false;
}
-
+
private:
TQueryArgProcessing& Parent;
TUri& Subject;
-
+
unsigned ArgsCount;
bool IsDirty;
-
+
static const unsigned MaxCount = 100;
};
-
+
TQueryArgProcessing::TQueryArgProcessing(ui32 flags, TQueryArgFilter filter, void* filterData)
: Flags(flags)
, Filter(filter)
, FilterData(filterData)
{
}
-
+
TQueryArg::EProcessed TQueryArgProcessing::Process(TUri& uri) {
Pipeline pipeline(*this, uri);
return pipeline.Process();
}
-}
+}
diff --git a/library/cpp/uri/qargs.h b/library/cpp/uri/qargs.h
index fcba7cbd0c..5dd9e43674 100644
--- a/library/cpp/uri/qargs.h
+++ b/library/cpp/uri/qargs.h
@@ -1,22 +1,22 @@
-#pragma once
-
-#include "common.h"
-#include "uri.h"
-#include <string>
-
-namespace NUri {
+#pragma once
+
+#include "common.h"
+#include "uri.h"
+#include <string>
+
+namespace NUri {
class TQueryArgProcessing {
public:
TQueryArgProcessing(ui32 flags, TQueryArgFilter filter = 0, void* filterData = 0);
-
+
TQueryArg::EProcessed Process(TUri& uri);
-
+
private:
ui32 Flags;
TQueryArgFilter Filter;
void* FilterData;
-
+
class Pipeline;
std::string Buffer;
};
-}
+}
diff --git a/library/cpp/uri/uri_ut.cpp b/library/cpp/uri/uri_ut.cpp
index 2ebd83fc93..d8f8fcfdc0 100644
--- a/library/cpp/uri/uri_ut.cpp
+++ b/library/cpp/uri/uri_ut.cpp
@@ -1,6 +1,6 @@
#include "uri_ut.h"
#include "other.h"
-#include "qargs.h"
+#include "qargs.h"
#include <library/cpp/html/entity/htmlentity.h>
#include <util/system/maxlen.h>
@@ -947,13 +947,13 @@ namespace NUri {
const char* skipName = static_cast<const char*>(filterData);
return arg.Name != skipName;
}
-
+
TString FilterQargs(TString url, const char* name) {
TString r;
ProcessQargs(url, r, &QueryArgsFilter, const_cast<char*>(name));
return r;
}
-
+
Y_UNIT_TEST_SUITE(QargsTest) {
Y_UNIT_TEST(TestSorting) {
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/"), "http://ya.ru/");
@@ -961,62 +961,62 @@ namespace NUri {
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?some=value"), "http://ya.ru/?some=value");
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?b=1&a=2"), "http://ya.ru/?a=2&b=1");
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?b=1&a=2&a=3"), "http://ya.ru/?a=3&a=2&b=1");
-
+
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?aaa=3&b=b&a=1&aa=2"), "http://ya.ru/?a=1&aa=2&aaa=3&b=b");
-
+
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?a=1&b=1&c=1"), "http://ya.ru/?a=1&b=1&c=1");
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?b=1&a=1&c=1"), "http://ya.ru/?a=1&b=1&c=1");
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?c=1&a=1&b=1"), "http://ya.ru/?a=1&b=1&c=1");
-
+
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?c=1&a=1&a=1&b=1&c=1&b=1"), "http://ya.ru/?a=1&a=1&b=1&b=1&c=1&c=1");
-
+
UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?b==&a=&&c="), "http://ya.ru/?a=&b==&c=");
}
-
+
Y_UNIT_TEST(TestParsingCorners) {
TString s;
-
- UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?=", s), TQueryArg::ProcessedOK);
- UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some", s), TQueryArg::ProcessedOK);
- UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some=", s), TQueryArg::ProcessedOK);
+
+ UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?=", s), TQueryArg::ProcessedOK);
+ UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some", s), TQueryArg::ProcessedOK);
+ UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some=", s), TQueryArg::ProcessedOK);
UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/", s), TQueryArg::ProcessedOK);
UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?&", s), TQueryArg::ProcessedOK);
UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?&&", s), TQueryArg::ProcessedOK);
UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some=", s), TQueryArg::ProcessedOK);
UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some==", s), TQueryArg::ProcessedOK);
UNIT_ASSERT_EQUAL(ProcessQargs("http://ya.ru/?some=&&", s), TQueryArg::ProcessedOK);
-
- UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?="), "http://ya.ru/?=");
- UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?some=="), "http://ya.ru/?some==");
- UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?&&"), "http://ya.ru/?&&");
- UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?a"), "http://ya.ru/?a");
+
+ UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?="), "http://ya.ru/?=");
+ UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?some=="), "http://ya.ru/?some==");
+ UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?&&"), "http://ya.ru/?&&");
+ UNIT_ASSERT_STRINGS_EQUAL(SortQargs("http://ya.ru/?a"), "http://ya.ru/?a");
}
-
+
Y_UNIT_TEST(TestFiltering) {
UNIT_ASSERT_STRINGS_EQUAL(FilterQargs("http://ya.ru/?some=value", "missing"), "http://ya.ru/?some=value");
UNIT_ASSERT_STRINGS_EQUAL(FilterQargs("http://ya.ru/?b=1&a=2", "b"), "http://ya.ru/?a=2");
UNIT_ASSERT_STRINGS_EQUAL(FilterQargs("http://ya.ru/?b=1&a=2&a=3", "a"), "http://ya.ru/?b=1");
UNIT_ASSERT_STRINGS_EQUAL(FilterQargs("http://ya.ru/?some=&another=", "another"), "http://ya.ru/?some=");
}
-
+
Y_UNIT_TEST(TestRemoveEmptyFeature) {
TUri uri;
uri.Parse("http://ya.ru/?", NUri::TFeature::FeaturesRecommended);
-
+
TQueryArgProcessing processing(TQueryArg::FeatureRemoveEmptyQuery | TQueryArg::FeatureRewriteDirty);
auto result = processing.Process(uri);
UNIT_ASSERT_EQUAL(result, TQueryArg::ProcessedOK);
UNIT_ASSERT_STRINGS_EQUAL(uri.PrintS(), "http://ya.ru/");
}
-
+
Y_UNIT_TEST(TestNoRemoveEmptyFeature) {
TUri uri;
uri.Parse("http://ya.ru/?", NUri::TFeature::FeaturesRecommended);
-
+
TQueryArgProcessing processing(0);
auto result = processing.Process(uri);
UNIT_ASSERT_EQUAL(result, TQueryArg::ProcessedOK);
UNIT_ASSERT_STRINGS_EQUAL(uri.PrintS(), "http://ya.ru/?");
}
}
-}
+}
diff --git a/library/cpp/uri/ya.make b/library/cpp/uri/ya.make
index 8fc808a6af..87ffae093f 100644
--- a/library/cpp/uri/ya.make
+++ b/library/cpp/uri/ya.make
@@ -13,7 +13,7 @@ SRCS(
location.cpp
other.cpp
parse.cpp
- qargs.cpp
+ qargs.cpp
uri.cpp
encodefsm.rl6
parsefsm.rl6