aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralbert <albert@yandex-team.ru>2022-02-10 16:48:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:15 +0300
commita817f5de12611ec73085eba17f8ec7740a46bdb7 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13
parent9f25ef3232c288ca664ceee6c376cf64e4349a2e (diff)
downloadydb-a817f5de12611ec73085eba17f8ec7740a46bdb7.tar.gz
Restoring authorship annotation for <albert@yandex-team.ru>. Commit 2 of 2.
-rwxr-xr-xbuild/scripts/touch.py92
-rw-r--r--contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp196
-rw-r--r--library/cpp/binsaver/bin_saver.h10
-rw-r--r--library/cpp/bit_io/bitinout_ut.cpp76
-rw-r--r--library/cpp/cgiparam/cgiparam.cpp54
-rw-r--r--library/cpp/cgiparam/cgiparam.h40
-rw-r--r--library/cpp/cgiparam/cgiparam_ut.cpp22
-rw-r--r--library/cpp/charset/codepage_ut.cpp22
-rw-r--r--library/cpp/charset/recyr.hh36
-rw-r--r--library/cpp/charset/recyr_int.hh12
-rw-r--r--library/cpp/charset/wide.h44
-rw-r--r--library/cpp/charset/wide_ut.cpp26
-rw-r--r--library/cpp/compproto/lib.cpp8
-rw-r--r--library/cpp/compproto/ya.make6
-rw-r--r--library/cpp/containers/compact_vector/compact_vector_ut.cpp20
-rw-r--r--library/cpp/containers/comptrie/comptrie_ut.cpp14
-rw-r--r--library/cpp/deprecated/accessors/accessors_ut.cpp2
-rw-r--r--library/cpp/deprecated/split/split_iterator.h16
-rw-r--r--library/cpp/digest/md5/md5.h10
-rw-r--r--library/cpp/execprofile/profile.cpp14
-rw-r--r--library/cpp/getopt/small/last_getopt.cpp4
-rw-r--r--library/cpp/getopt/small/last_getopt.h6
-rw-r--r--library/cpp/getopt/small/last_getopt_support.h12
-rw-r--r--library/cpp/getopt/small/opt.cpp10
-rw-r--r--library/cpp/getopt/small/opt.h2
-rw-r--r--library/cpp/getopt/small/posix_getopt.cpp4
-rw-r--r--library/cpp/getopt/ut/last_getopt_ut.cpp86
-rw-r--r--library/cpp/getopt/ut/opt2_ut.cpp2
-rw-r--r--library/cpp/html/pcdata/pcdata.cpp4
-rw-r--r--library/cpp/string_utils/quote/quote.cpp20
-rw-r--r--library/cpp/string_utils/quote/quote.h8
-rw-r--r--library/cpp/string_utils/scan/scan.h6
-rw-r--r--library/cpp/string_utils/url/url.cpp12
-rw-r--r--library/cpp/testing/unittest/registar.h14
-rw-r--r--library/cpp/uri/assign.cpp160
-rw-r--r--library/cpp/uri/common.cpp20
-rw-r--r--library/cpp/uri/common.h174
-rw-r--r--library/cpp/uri/encode.cpp110
-rw-r--r--library/cpp/uri/encode.h50
-rw-r--r--library/cpp/uri/encodefsm.rl646
-rw-r--r--library/cpp/uri/http_url.h100
-rw-r--r--library/cpp/uri/other.cpp6
-rw-r--r--library/cpp/uri/parse.cpp70
-rw-r--r--library/cpp/uri/parse.h136
-rw-r--r--library/cpp/uri/parsefsm.rl6870
-rw-r--r--library/cpp/uri/uri-ru_ut.cpp24
-rw-r--r--library/cpp/uri/uri.cpp114
-rw-r--r--library/cpp/uri/uri.h182
-rw-r--r--library/cpp/uri/uri_ut.cpp162
-rw-r--r--library/cpp/uri/uri_ut.h42
-rw-r--r--library/cpp/uri/ya.make30
-rw-r--r--library/cpp/xml/document/node-attr.h2
-rw-r--r--util/charset/wide.h24
-rw-r--r--util/folder/dirut_ut.cpp6
-rw-r--r--util/generic/strbase.h42
-rw-r--r--util/generic/strbuf.cpp6
-rw-r--r--util/generic/strbuf.h216
-rw-r--r--util/generic/strbuf_ut.cpp48
-rw-r--r--util/generic/string.h90
-rw-r--r--util/generic/typetraits.h2
-rw-r--r--util/generic/yexception.h8
-rw-r--r--util/memory/tempbuf.cpp16
-rw-r--r--util/stream/format.h10
-rw-r--r--util/stream/mem.cpp4
-rw-r--r--util/stream/mem.h154
-rw-r--r--util/stream/output.h4
-rw-r--r--util/string/util.h16
-rw-r--r--util/system/atomic_ut.cpp142
-rw-r--r--util/system/cpu_id.cpp18
-rw-r--r--util/system/file_ut.cpp4
-rw-r--r--util/system/maxlen.h8
-rw-r--r--util/system/platform.h2
-rw-r--r--util/system/tls.h78
73 files changed, 2053 insertions, 2053 deletions
diff --git a/build/scripts/touch.py b/build/scripts/touch.py
index 4c9296e65d..e01ba7f86b 100755
--- a/build/scripts/touch.py
+++ b/build/scripts/touch.py
@@ -1,50 +1,50 @@
-#!/usr/bin/env python
-
-import optparse
-import os
-import sys
-import time
-
-
-def main(argv):
+#!/usr/bin/env python
+
+import optparse
+import os
+import sys
+import time
+
+
+def main(argv):
parser = optparse.OptionParser(add_help_option=False)
- parser.disable_interspersed_args()
-
+ parser.disable_interspersed_args()
+
parser.add_option('-?', '--help', dest='help',
action='store_true', default=None, help='print help')
parser.add_option('-t', dest='t', action='store', default=None)
-
- opts, argv_rest = parser.parse_args(argv)
- if getattr(opts, 'help', False):
- parser.print_help()
- return 0
-
- tspec = opts.t
- if tspec is None:
- times = None
- else:
- head, sep, tail = tspec.partition('.')
- if 8 > len(head):
- raise Exception("time spec must follow format [[CC]YY]MMDDhhmm[.SS]: " + tspec + '; ' + head)
- tfmt = ''
- if 12 == len(head):
- tfmt += '%Y'
- elif 10 == len(head):
- tfmt += '%y'
- tfmt += '%m%d%H%M'
- if 2 == len(tail):
- tfmt += '.%S'
- mtime = time.mktime(time.strptime(tspec, tfmt))
- times = (mtime, mtime)
-
- for file in argv_rest:
- try:
- os.utime(file, times)
- except:
- open(file, 'w').close()
- if times is not None:
- os.utime(file, times)
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
+
+ opts, argv_rest = parser.parse_args(argv)
+ if getattr(opts, 'help', False):
+ parser.print_help()
+ return 0
+
+ tspec = opts.t
+ if tspec is None:
+ times = None
+ else:
+ head, sep, tail = tspec.partition('.')
+ if 8 > len(head):
+ raise Exception("time spec must follow format [[CC]YY]MMDDhhmm[.SS]: " + tspec + '; ' + head)
+ tfmt = ''
+ if 12 == len(head):
+ tfmt += '%Y'
+ elif 10 == len(head):
+ tfmt += '%y'
+ tfmt += '%m%d%H%M'
+ if 2 == len(tail):
+ tfmt += '.%S'
+ mtime = time.mktime(time.strptime(tspec, tfmt))
+ times = (mtime, mtime)
+
+ for file in argv_rest:
+ try:
+ os.utime(file, times)
+ except:
+ open(file, 'w').close()
+ if times is not None:
+ os.utime(file, times)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
diff --git a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp
index b4d37eb4f4..cd96aa0565 100644
--- a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp
+++ b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp
@@ -110,8 +110,8 @@ namespace NPlugins {
printer->Print(Variables_,
"inline const $type$& Get$rname$() const { return $name$(); }\n"
"inline $type$* Mutable$rname$() { return mutable_$name$(); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline const $type$& Get$RName$() const { return $name$(); }\n"
"inline $type$* Mutable$RName$() { return mutable_$name$(); }\n");
}
@@ -218,9 +218,9 @@ namespace NPlugins {
" Get$rname$() const { return $name$(); }\n"
"inline ::google::protobuf::RepeatedPtrField< $type$ >*\n"
" Mutable$rname$() { return mutable_$name$(); }\n");
-
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline const $type$& Get$RName$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(int(_index)); }\n"
"inline $type$* Mutable$RName$(size_t _index) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return mutable_$name$(int(_index)); }\n"
"inline $type$* Add$RName$() { return add_$name$(); }\n"
@@ -228,7 +228,7 @@ namespace NPlugins {
" Get$RName$() const { return $name$(); }\n"
"inline ::google::protobuf::RepeatedPtrField< $type$ >*\n"
" Mutable$RName$() { return mutable_$name$(); }\n"
- );
+ );
}
void GenerateJSONPrinting(io::Printer* printer) override {
@@ -262,16 +262,16 @@ namespace NPlugins {
"inline void Set$rname$(const $pointer_type$* value, size_t size) { set_$name$(value, size); }\n"
"inline TProtoStringType* Mutable$rname$() { return mutable_$name$(); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline const TProtoStringType& Get$RName$() const { return $name$(); }\n"
"inline void Set$RName$(const TProtoStringType& value) { set_$name$(value); }\n"
"inline void Set$RName$(TProtoStringType&& value) { set_$name$(std::move(value)); }\n"
"inline void Set$RName$(const char* value) { set_$name$(value); }\n"
"inline void Set$RName$(const $pointer_type$* value, size_t size) { set_$name$(value, size); }\n"
"inline TProtoStringType* Mutable$RName$() { return mutable_$name$(); }\n"
- );
-
+ );
+
if (Field_->options().ctype() != FieldOptions::STRING) {
printer->Outdent();
printer->Print(" public:\n");
@@ -317,14 +317,14 @@ namespace NPlugins {
"inline void Add$rname$(const $pointer_type$* value, size_t size) { add_$name$(value, size); }\n"
"inline const TProtoStringType& get_idx_$name$(int _index) const { return $name$(_index); }\n"
"inline const ::google::protobuf::RepeatedPtrField<TProtoStringType>& get_arr_$name$() const"
- "{ return $name$(); }\n"
+ "{ return $name$(); }\n"
"inline const ::google::protobuf::RepeatedPtrField<TProtoStringType>& Get$rname$() const"
"{ return $name$(); }\n"
"inline ::google::protobuf::RepeatedPtrField<TProtoStringType>* Mutable$rname$()"
"{ return mutable_$name$(); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline const TProtoStringType& Get$RName$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n"
"inline TProtoStringType* Mutable$RName$(size_t _index) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return mutable_$name$(_index); }\n"
"inline void Set$RName$(size_t _index, const TProtoStringType& value) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); set_$name$(_index, value); }\n"
@@ -337,11 +337,11 @@ namespace NPlugins {
"inline void Add$RName$(const char* value) { add_$name$(value); }\n"
"inline void Add$RName$(const $pointer_type$* value, size_t size) { add_$name$(value, size); }\n"
"inline const ::google::protobuf::RepeatedPtrField<TProtoStringType>& Get$RName$() const"
- "{ return $name$(); }\n"
+ "{ return $name$(); }\n"
"inline ::google::protobuf::RepeatedPtrField<TProtoStringType>* Mutable$RName$()"
- "{ return mutable_$name$(); }\n"
- );
-
+ "{ return mutable_$name$(); }\n"
+ );
+
if (Field_->options().ctype() != FieldOptions::STRING) {
printer->Outdent();
printer->Print(" public:\n");
@@ -371,11 +371,11 @@ namespace NPlugins {
"inline $type$ Get$rname$() const { return $name$(); }\n"
"inline void Set$rname$($type$ value) { set_$name$(value); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline $type$ Get$RName$() const { return $name$(); } \n"
"inline void Set$RName$($type$ value) { set_$name$(value); }\n"
- );
+ );
}
void GenerateJSONPrinting(io::Printer* printer) override {
@@ -401,14 +401,14 @@ namespace NPlugins {
"inline const ::google::protobuf::RepeatedField<int>& get_arr_$name$() const { return $name$(); }\n"
"inline const ::google::protobuf::RepeatedField<int>& Get$rname$() const { return $name$(); }\n"
"inline ::google::protobuf::RepeatedField<int>* Mutable$rname$() { return mutable_$name$(); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline $type$ Get$RName$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n"
"inline void Set$RName$(size_t _index, $type$ value) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); set_$name$(_index, value); }\n"
"inline void Add$RName$($type$ value) { add_$name$(value); }\n"
"inline const ::google::protobuf::RepeatedField<int>& Get$RName$() const { return $name$(); }\n"
"inline ::google::protobuf::RepeatedField<int>* Mutable$RName$() { return mutable_$name$(); }\n"
- );
+ );
}
void GenerateJSONPrinting(io::Printer* printer) override {
@@ -429,11 +429,11 @@ namespace NPlugins {
printer->Print(Variables_,
"inline $type$ Get$rname$() const { return $name$();}\n"
"inline void Set$rname$($type$ value) { set_$name$(value); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline $type$ Get$RName$() const { return $name$();}\n"
"inline void Set$RName$($type$ value) { set_$name$(value); }\n"
- );
+ );
}
void GenerateJSONPrinting(io::Printer* printer) override {
@@ -462,8 +462,8 @@ namespace NPlugins {
" Get$rname$() const { return $name$(); }\n"
"inline ::google::protobuf::RepeatedField< $type$ >*\n"
" Mutable$rname$() { return mutable_$name$(); }\n");
- if (Variables_.end() != Variables_.find("RName"))
- printer->Print(Variables_,
+ if (Variables_.end() != Variables_.find("RName"))
+ printer->Print(Variables_,
"inline $type$ Get$RName$(size_t _index) const {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); return $name$(_index); }\n"
"inline void Set$RName$(size_t _index, $type$ value) {Y_ASSERT(_index < static_cast<size_t>(::Max<int>())); set_$name$(_index, value); }\n"
"inline void Add$RName$($type$ value) { add_$name$(value); }\n"
@@ -471,7 +471,7 @@ namespace NPlugins {
" Get$RName$() const { return $name$(); }\n"
"inline ::google::protobuf::RepeatedField< $type$ >*\n"
" Mutable$RName$() { return mutable_$name$(); }\n"
- );
+ );
}
void GenerateJSONPrinting(io::Printer* printer) override {
@@ -527,63 +527,63 @@ namespace NPlugins {
}
};
- // borrowed mostly from protobuf/compiler/cpp/cpp_extension.cc
- class TExtensionGenerator {
- public:
- TExtensionGenerator(const FieldDescriptor* descriptor)
- : Descriptor_(descriptor)
- {
- if (Descriptor_->is_repeated()) {
- type_traits_ = "Repeated";
- }
-
- TProtoStringType clsName;
- switch (Descriptor_->cpp_type()) {
- case FieldDescriptor::CPPTYPE_ENUM:
- type_traits_.append("EnumTypeTraits< ");
- clsName = ClassName(Descriptor_->enum_type(), true);
- type_traits_.append(clsName);
- type_traits_.append(", ");
- type_traits_.append(clsName);
- type_traits_.append("_IsValid>");
- break;
- case FieldDescriptor::CPPTYPE_STRING:
- type_traits_.append("StringTypeTraits");
- break;
- case FieldDescriptor::CPPTYPE_MESSAGE:
- type_traits_.append("MessageTypeTraits< ");
- type_traits_.append(ClassName(Descriptor_->message_type(), true));
- type_traits_.append(" >");
- break;
- default:
- type_traits_.append("PrimitiveTypeTraits< ");
- type_traits_.append(PrimitiveTypeName(Descriptor_->cpp_type()));
- type_traits_.append(" >");
- break;
- }
- }
-
- void GenerateDeclaration(io::Printer* printer) const
- {
- TVariables vars;
- vars["extendee" ] = ClassName(Descriptor_->containing_type(), true);
- vars["type_traits" ] = type_traits_;
- vars["name" ] = Descriptor_->name();
- vars["field_type" ] = SimpleItoa(static_cast<int>(Descriptor_->type()));
- vars["packed" ] = Descriptor_->options().packed() ? "true" : "false";
-
- printer->Print(vars,
- "typedef ::google::protobuf::internal::ExtensionIdentifier< $extendee$,\n"
- " ::google::protobuf::internal::$type_traits$, $field_type$, $packed$ >\n"
- " Td$name$;\n"
- );
- }
-
- private:
- const FieldDescriptor* Descriptor_;
- TProtoStringType type_traits_;
- };
-
+ // borrowed mostly from protobuf/compiler/cpp/cpp_extension.cc
+ class TExtensionGenerator {
+ public:
+ TExtensionGenerator(const FieldDescriptor* descriptor)
+ : Descriptor_(descriptor)
+ {
+ if (Descriptor_->is_repeated()) {
+ type_traits_ = "Repeated";
+ }
+
+ TProtoStringType clsName;
+ switch (Descriptor_->cpp_type()) {
+ case FieldDescriptor::CPPTYPE_ENUM:
+ type_traits_.append("EnumTypeTraits< ");
+ clsName = ClassName(Descriptor_->enum_type(), true);
+ type_traits_.append(clsName);
+ type_traits_.append(", ");
+ type_traits_.append(clsName);
+ type_traits_.append("_IsValid>");
+ break;
+ case FieldDescriptor::CPPTYPE_STRING:
+ type_traits_.append("StringTypeTraits");
+ break;
+ case FieldDescriptor::CPPTYPE_MESSAGE:
+ type_traits_.append("MessageTypeTraits< ");
+ type_traits_.append(ClassName(Descriptor_->message_type(), true));
+ type_traits_.append(" >");
+ break;
+ default:
+ type_traits_.append("PrimitiveTypeTraits< ");
+ type_traits_.append(PrimitiveTypeName(Descriptor_->cpp_type()));
+ type_traits_.append(" >");
+ break;
+ }
+ }
+
+ void GenerateDeclaration(io::Printer* printer) const
+ {
+ TVariables vars;
+ vars["extendee" ] = ClassName(Descriptor_->containing_type(), true);
+ vars["type_traits" ] = type_traits_;
+ vars["name" ] = Descriptor_->name();
+ vars["field_type" ] = SimpleItoa(static_cast<int>(Descriptor_->type()));
+ vars["packed" ] = Descriptor_->options().packed() ? "true" : "false";
+
+ printer->Print(vars,
+ "typedef ::google::protobuf::internal::ExtensionIdentifier< $extendee$,\n"
+ " ::google::protobuf::internal::$type_traits$, $field_type$, $packed$ >\n"
+ " Td$name$;\n"
+ );
+ }
+
+ private:
+ const FieldDescriptor* Descriptor_;
+ TProtoStringType type_traits_;
+ };
+
class TOneofGenerator {
public:
TOneofGenerator(const OneofDescriptor* Descriptor_)
@@ -670,11 +670,11 @@ namespace NPlugins {
for (int i = 0; i < descriptor->field_count(); i++) {
FieldGenerators_.emplace_back(MakeGenerator(descriptor->field(i)));
}
-
+
ExtensionGenerators_.reserve(descriptor->extension_count());
- for (int i = 0; i < descriptor->extension_count(); i++) {
+ for (int i = 0; i < descriptor->extension_count(); i++) {
ExtensionGenerators_.emplace_back(descriptor->extension(i));
- }
+ }
OneofGenerators_.reserve(descriptor->real_oneof_decl_count());
for (int i = 0; i < descriptor->real_oneof_decl_count(); i++) {
@@ -737,31 +737,31 @@ namespace NPlugins {
OutputDirectory_->OpenForInsert(fileName, scope));
io::Printer printer(output.get(), '$');
- printer.Print("// Yandex cpp-styleguide extension\n");
+ printer.Print("// Yandex cpp-styleguide extension\n");
for (int i = 0; i < Descriptor_->field_count(); i++) {
const FieldDescriptor* field = Descriptor_->field(i);
TVariables vars;
SetCommonFieldVariables(field, &vars);
- const bool hasRName = (vars.end() != vars.find("RName"));
+ const bool hasRName = (vars.end() != vars.find("RName"));
if (field->is_repeated()) {
printer.Print(vars,
"inline size_t $rname$Size() const { return (size_t)$name$_size(); }\n");
- if (hasRName)
- printer.Print(vars,
+ if (hasRName)
+ printer.Print(vars,
"inline size_t $RName$Size() const { return (size_t)$name$_size(); }\n");
} else if (field->has_presence()) {
printer.Print(vars,
"inline bool Has$rname$() const { return has_$name$(); }\n");
- if (hasRName)
- printer.Print(vars,
+ if (hasRName)
+ printer.Print(vars,
"inline bool Has$RName$() const { return has_$name$(); }\n");
}
printer.Print(vars, "inline void Clear$rname$() { clear_$name$(); }\n");
- if (hasRName)
- printer.Print(vars,
+ if (hasRName)
+ printer.Print(vars,
"inline void Clear$RName$() { clear_$name$(); }\n");
// Generate type-specific accessor declarations.
@@ -771,7 +771,7 @@ namespace NPlugins {
}
for (auto& extensionGenerator: ExtensionGenerators_) {
extensionGenerator.GenerateDeclaration(&printer);
- }
+ }
for (auto& oneofGenerator: OneofGenerators_) {
oneofGenerator.GenerateDeclarations(&printer);
}
diff --git a/library/cpp/binsaver/bin_saver.h b/library/cpp/binsaver/bin_saver.h
index fde6358047..412424889f 100644
--- a/library/cpp/binsaver/bin_saver.h
+++ b/library/cpp/binsaver/bin_saver.h
@@ -602,7 +602,7 @@ struct TRegisterSaveLoadType {
#define REGISTER_SAVELOAD_NM_CLASS(N, nmspace, className) \
BASIC_REGISTER_CLASS(nmspace::className) \
static TRegisterSaveLoadType<nmspace::className> init_##nmspace##_##name##N(N);
-
+
#define REGISTER_SAVELOAD_NM2_CLASS(N, nmspace1, nmspace2, className) \
BASIC_REGISTER_CLASS(nmspace1::nmspace2::className) \
static TRegisterSaveLoadType<nmspace1::nmspace2::className> init_##nmspace1##_##nmspace2##_##name##N(N);
@@ -611,12 +611,12 @@ struct TRegisterSaveLoadType {
typedef nmspace::className<T> temp_init##nmspace##className##T##temp; \
BASIC_REGISTER_CLASS(nmspace::className<T>) \
static TRegisterSaveLoadType<nmspace::className<T>> temp_init##nmspace##_##name##T##N(N);
-
-#define REGISTER_SAVELOAD_CLASS_NAME(N, cls, name) \
+
+#define REGISTER_SAVELOAD_CLASS_NAME(N, cls, name) \
BASIC_REGISTER_CLASS(cls) \
static TRegisterSaveLoadType<cls> init##name##N(N);
-
-#define REGISTER_SAVELOAD_CLASS_NS_PREF(N, cls, ns, pref) \
+
+#define REGISTER_SAVELOAD_CLASS_NS_PREF(N, cls, ns, pref) \
REGISTER_SAVELOAD_CLASS_NAME(N, ns ::cls, _##pref##_##cls)
#define SAVELOAD(...) \
diff --git a/library/cpp/bit_io/bitinout_ut.cpp b/library/cpp/bit_io/bitinout_ut.cpp
index 77762e7487..23a1ddf344 100644
--- a/library/cpp/bit_io/bitinout_ut.cpp
+++ b/library/cpp/bit_io/bitinout_ut.cpp
@@ -82,42 +82,42 @@ private:
template <typename TBo>
void DoWrite1(TBo& out, const TString& rem) {
out.Write(0x0C, 3);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 1u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 1u, (rem + ", " + ToString(__LINE__)));
out.Write(0x18, 4);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 1u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 1u, (rem + ", " + ToString(__LINE__)));
out.Write(0x0C, 3);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 2u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 2u, (rem + ", " + ToString(__LINE__)));
out.Write(0x30000, 17);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 4u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 4u, (rem + ", " + ToString(__LINE__)));
out.Write(0x0C, 3);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 4u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 4u, (rem + ", " + ToString(__LINE__)));
}
template <typename TBo>
void DoWrite2(TBo& out, const TString& rem) {
out.Write(0x0C, 3);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 8u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 8u, (rem + ", " + ToString(__LINE__)));
out.Write(0x42, 7);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 9u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 9u, (rem + ", " + ToString(__LINE__)));
DoWrite(out, 1637415112);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 13u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 13u, (rem + ", " + ToString(__LINE__)));
DoWrite(out, 897998715);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 17u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 17u, (rem + ", " + ToString(__LINE__)));
DoWrite(out, 201416527);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 21u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 21u, (rem + ", " + ToString(__LINE__)));
DoWrite(out, 432344219);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 25u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 25u, (rem + ", " + ToString(__LINE__)));
out.Write(0xAAAAAAAAAAAAAAAAULL, 64);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 33u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 33u, (rem + ", " + ToString(__LINE__)));
out.Write(0x5555555555555555ULL, 64);
- UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 41u, (rem + ", " + ToString(__LINE__)));
+ UNIT_ASSERT_VALUES_EQUAL_C(out.GetOffset(), 41u, (rem + ", " + ToString(__LINE__)));
}
void DoBitOutput(NBitIO::TBitOutputYVector& out, const TString& rem) {
@@ -145,36 +145,36 @@ private:
ui64 val;
val = 0;
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 0u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 0u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(in.Read(val, 3), (rem + ": " + NBitIO::PrintBits(val)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 1u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 1u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
val = 0;
UNIT_ASSERT_C(in.Read(val, 4), (rem + ": " + NBitIO::PrintBits(val)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x8u, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 1u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x8u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 1u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
val = 0;
UNIT_ASSERT_C(in.Read(val, 3), (rem + ": " + NBitIO::PrintBits(val)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 2u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 2u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
val = 0;
UNIT_ASSERT_C(in.Read(val, 17), (rem + ": " + NBitIO::PrintBits(val)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x10000u, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x10000u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 4u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 4u, (rem + ": " + NBitIO::PrintBits(val)));
{
ui32 rt = 0;
@@ -184,56 +184,56 @@ private:
val = 0;
UNIT_ASSERT_C(in.Read(val, 3), (rem + ": " + NBitIO::PrintBits(val)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 4u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
val = 0;
UNIT_ASSERT_C(in.ReadWords<8>(val), (rem + ": " + NBitIO::PrintBits(val)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0xabcdefU, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 8u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0xabcdefU, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 8u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
val = 0;
UNIT_ASSERT_C(in.Read(val, 3), (rem + ", " + ToString(__LINE__)).data());
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 8u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x4u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 8u, (rem + ": " + NBitIO::PrintBits(val)));
UNIT_ASSERT_C(!in.Eof(), (rem + ", " + ToString(__LINE__)).data());
val = 0;
in.Read(val, 7);
- UNIT_ASSERT_VALUES_EQUAL_C(val, 0x42u, (rem + ": " + NBitIO::PrintBits(val)));
+ UNIT_ASSERT_VALUES_EQUAL_C(val, 0x42u, (rem + ": " + NBitIO::PrintBits(val)));
}
{
ui32 v = 0;
DoRead(in, v);
- UNIT_ASSERT_VALUES_EQUAL_C(v, 1637415112ul, (rem + ": " + NBitIO::PrintBits(v)));
+ UNIT_ASSERT_VALUES_EQUAL_C(v, 1637415112ul, (rem + ": " + NBitIO::PrintBits(v)));
DoRead(in, v);
UNIT_ASSERT_VALUES_EQUAL_C(v, 897998715u, (rem + ": " + NBitIO::PrintBits(v)));
DoRead(in, v);
- UNIT_ASSERT_VALUES_EQUAL_C(v, 201416527u, (rem + ": " + NBitIO::PrintBits(v)));
+ UNIT_ASSERT_VALUES_EQUAL_C(v, 201416527u, (rem + ": " + NBitIO::PrintBits(v)));
DoRead(in, v);
- UNIT_ASSERT_VALUES_EQUAL_C(v, 432344219u, (rem + ": " + NBitIO::PrintBits(v)));
+ UNIT_ASSERT_VALUES_EQUAL_C(v, 432344219u, (rem + ": " + NBitIO::PrintBits(v)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 25u, (rem + ": " + NBitIO::PrintBits(v)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 25u, (rem + ": " + NBitIO::PrintBits(v)));
}
{
ui64 v8 = 0;
in.ReadSafe(v8, 64);
- UNIT_ASSERT_VALUES_EQUAL_C(v8, 0xAAAAAAAAAAAAAAAAULL, (rem + ": " + NBitIO::PrintBits(v8)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 33u, (rem + ": " + NBitIO::PrintBits(v8)));
+ UNIT_ASSERT_VALUES_EQUAL_C(v8, 0xAAAAAAAAAAAAAAAAULL, (rem + ": " + NBitIO::PrintBits(v8)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 33u, (rem + ": " + NBitIO::PrintBits(v8)));
v8 = 0;
in.ReadK<64>(v8);
- UNIT_ASSERT_VALUES_EQUAL_C(v8, 0x5555555555555555ULL, (rem + ": " + NBitIO::PrintBits(v8)));
- UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 41u, (rem + ": " + NBitIO::PrintBits(v8)));
+ UNIT_ASSERT_VALUES_EQUAL_C(v8, 0x5555555555555555ULL, (rem + ": " + NBitIO::PrintBits(v8)));
+ UNIT_ASSERT_VALUES_EQUAL_C(in.GetOffset(), 41u, (rem + ": " + NBitIO::PrintBits(v8)));
}
ui32 v = 0;
diff --git a/library/cpp/cgiparam/cgiparam.cpp b/library/cpp/cgiparam/cgiparam.cpp
index 2170bce69e..f3277b8e4b 100644
--- a/library/cpp/cgiparam/cgiparam.cpp
+++ b/library/cpp/cgiparam/cgiparam.cpp
@@ -21,13 +21,13 @@ bool TCgiParameters::Erase(const TStringBuf name, size_t pos) {
const auto pair = equal_range(name);
for (auto it = pair.first; it != pair.second; ++it, --pos) {
- if (0 == pos) {
- erase(it);
- return true;
- }
+ if (0 == pos) {
+ erase(it);
+ return true;
+ }
}
- return false;
+ return false;
}
bool TCgiParameters::Erase(const TStringBuf name, const TStringBuf val) {
@@ -47,21 +47,21 @@ bool TCgiParameters::Erase(const TStringBuf name, const TStringBuf val) {
}
size_t TCgiParameters::EraseAll(const TStringBuf name) {
- size_t num = 0;
+ size_t num = 0;
const auto pair = equal_range(name);
for (auto it = pair.first; it != pair.second; erase(it++), ++num)
- ;
+ ;
+
+ return num;
+}
- return num;
-}
-
void TCgiParameters::JoinUnescaped(const TStringBuf key, char sep, TStringBuf val) {
const auto pair = equal_range(key);
auto it = pair.first;
- if (it == pair.second) { // not found
+ if (it == pair.second) { // not found
if (val.IsInited()) {
emplace_hint(it, TString(key), TString(val));
}
@@ -69,17 +69,17 @@ void TCgiParameters::JoinUnescaped(const TStringBuf key, char sep, TStringBuf va
TString& dst = it->second;
for (++it; it != pair.second; erase(it++)) {
- dst += sep;
+ dst += sep;
dst.AppendNoAlias(it->second.data(), it->second.size());
- }
-
- if (val.IsInited()) {
- dst += sep;
- dst += val;
- }
- }
-}
-
+ }
+
+ if (val.IsInited()) {
+ dst += sep;
+ dst += val;
+ }
+ }
+}
+
static inline TString DoUnescape(const TStringBuf s) {
TString res;
@@ -155,18 +155,18 @@ char* TCgiParameters::Print(char* res) const {
}
for (auto i = begin();;) {
- res = CGIEscape(res, i->first);
+ res = CGIEscape(res, i->first);
*res++ = '=';
- res = CGIEscape(res, i->second);
+ res = CGIEscape(res, i->second);
if (++i == end()) {
- break;
+ break;
}
*res++ = '&';
}
- return res;
+ return res;
}
size_t TCgiParameters::PrintSize() const noexcept {
@@ -209,11 +209,11 @@ TCgiParameters::const_iterator TCgiParameters::Find(const TStringBuf name, size_
for (auto it = pair.first; it != pair.second; ++it, --pos) {
if (0 == pos) {
- return it;
+ return it;
}
}
- return end();
+ return end();
}
bool TCgiParameters::Has(const TStringBuf name, const TStringBuf value) const noexcept {
diff --git a/library/cpp/cgiparam/cgiparam.h b/library/cpp/cgiparam/cgiparam.h
index 6d87d278e7..87d1ab0ad4 100644
--- a/library/cpp/cgiparam/cgiparam.h
+++ b/library/cpp/cgiparam/cgiparam.h
@@ -4,7 +4,7 @@
#include <util/generic/iterator_range.h>
#include <util/generic/map.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/strbuf.h>
#include <util/generic/string.h>
#include <initializer_list>
@@ -17,28 +17,28 @@ struct TStringLess {
};
class TCgiParameters: public TMultiMap<TString, TString> {
-public:
+public:
TCgiParameters() = default;
explicit TCgiParameters(const TStringBuf cgiParamStr) {
Scan(cgiParamStr);
- }
+ }
TCgiParameters(std::initializer_list<std::pair<TString, TString>> il);
- void Flush() {
- erase(begin(), end());
- }
+ void Flush() {
+ erase(begin(), end());
+ }
size_t EraseAll(const TStringBuf name);
size_t NumOfValues(const TStringBuf name) const noexcept {
- return count(name);
- }
+ return count(name);
+ }
TString operator()() const {
- return Print();
- }
+ return Print();
+ }
void Scan(const TStringBuf cgiParStr, bool form = true);
void ScanAdd(const TStringBuf cgiParStr);
@@ -52,7 +52,7 @@ public:
* @note Names and values in the returned string are CGI-escaped.
*/
TString Print() const;
- char* Print(char* res) const;
+ char* Print(char* res) const;
Y_PURE_FUNCTION
size_t PrintSize() const noexcept;
@@ -65,7 +65,7 @@ public:
Y_PURE_FUNCTION
auto Range(const TStringBuf name) const noexcept {
return IterateValues(MakeIteratorRange(equal_range(name)));
- }
+ }
Y_PURE_FUNCTION
const_iterator Find(const TStringBuf name, size_t numOfValue = 0) const noexcept;
@@ -95,7 +95,7 @@ public:
// is not implicitly constructible from given type.
// But libc++ pair allows this with C++14.
emplace(std::forward<TName>(name), std::forward<TValue>(value));
- }
+ }
#else
template <typename TName, typename TValue>
inline void InsertUnescaped(TName&& name, TValue&& value) {
@@ -106,7 +106,7 @@ public:
// replace all values for a given key with new values
template <typename TIter>
void ReplaceUnescaped(const TStringBuf key, TIter valuesBegin, const TIter valuesEnd);
-
+
void ReplaceUnescaped(const TStringBuf key, std::initializer_list<TStringBuf> values) {
ReplaceUnescaped(key, values.begin(), values.end());
}
@@ -116,21 +116,21 @@ public:
}
// join multiple values into a single one using a separator
- // if val is a [possibly empty] non-NULL string, append it as well
+ // if val is a [possibly empty] non-NULL string, append it as well
void JoinUnescaped(const TStringBuf key, char sep, TStringBuf val = TStringBuf());
-
+
bool Erase(const TStringBuf name, size_t numOfValue = 0);
bool Erase(const TStringBuf name, const TStringBuf val);
inline const char* FormField(const TStringBuf name, size_t numOfValue = 0) const {
- const_iterator it = Find(name, numOfValue);
+ const_iterator it = Find(name, numOfValue);
- if (it == end()) {
+ if (it == end()) {
return nullptr;
}
-
+
return it->second.data();
- }
+ }
};
template <typename TIter>
diff --git a/library/cpp/cgiparam/cgiparam_ut.cpp b/library/cpp/cgiparam/cgiparam_ut.cpp
index 603dfd3eda..a562342084 100644
--- a/library/cpp/cgiparam/cgiparam_ut.cpp
+++ b/library/cpp/cgiparam/cgiparam_ut.cpp
@@ -60,7 +60,7 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
TCgiParameters c;
c.ScanAddAll("qw");
- UNIT_ASSERT_VALUES_EQUAL(c.size(), 1u);
+ UNIT_ASSERT_VALUES_EQUAL(c.size(), 1u);
UNIT_ASSERT(c.Get("qw").empty());
}
@@ -68,7 +68,7 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
TCgiParameters c;
c.ScanAddAll("qw&");
- UNIT_ASSERT_VALUES_EQUAL(c.size(), 1u);
+ UNIT_ASSERT_VALUES_EQUAL(c.size(), 1u);
UNIT_ASSERT(c.Get("qw").empty());
}
@@ -76,7 +76,7 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
TCgiParameters c;
c.ScanAddAll("qw=1&x");
- UNIT_ASSERT_VALUES_EQUAL(c.size(), 2u);
+ UNIT_ASSERT_VALUES_EQUAL(c.size(), 2u);
UNIT_ASSERT_VALUES_EQUAL(c.Get("qw"), "1");
UNIT_ASSERT(c.Get("x").empty());
}
@@ -182,7 +182,7 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
TCgiParameters c;
c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3");
- UNIT_ASSERT_VALUES_EQUAL(c.NumOfValues("par"), 3u);
+ UNIT_ASSERT_VALUES_EQUAL(c.NumOfValues("par"), 3u);
}
Y_UNIT_TEST(TestUnscape) {
@@ -193,16 +193,16 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) {
Y_UNIT_TEST(TestEmpty) {
UNIT_ASSERT(TCgiParameters().Print().empty());
}
-
+
Y_UNIT_TEST(TestJoinUnescaped) {
- TCgiParameters c;
-
+ TCgiParameters c;
+
c.Scan("foo=1&foo=2");
c.JoinUnescaped("foo", ';', "0");
-
- UNIT_ASSERT_VALUES_EQUAL(c.Print(), "foo=1;2;0");
- }
-
+
+ UNIT_ASSERT_VALUES_EQUAL(c.Print(), "foo=1;2;0");
+ }
+
Y_UNIT_TEST(TestContInit) {
TCgiParameters c = {std::make_pair("a", "a1"), std::make_pair("b", "b1"), std::make_pair("a", "a2")};
diff --git a/library/cpp/charset/codepage_ut.cpp b/library/cpp/charset/codepage_ut.cpp
index 47ec1fb2c5..c3ac3ac478 100644
--- a/library/cpp/charset/codepage_ut.cpp
+++ b/library/cpp/charset/codepage_ut.cpp
@@ -69,7 +69,7 @@ public:
}
void TestBrokenRune() {
- UNIT_ASSERT_VALUES_EQUAL(BROKEN_RUNE, 0xFFFDu);
+ UNIT_ASSERT_VALUES_EQUAL(BROKEN_RUNE, 0xFFFDu);
}
};
@@ -198,17 +198,17 @@ void TCodepageTest::TestUTFFromUnknownPlane() {
UNIT_ASSERT(res == RECODE_OK);
UNIT_ASSERT(samplelen == readchars);
- size_t writtenbytes2 = 0;
- char bytebuffer2[BUFFER_SIZE];
- for (size_t i = 0; i != samplelen; ++i) {
- size_t nwr = 0;
+ size_t writtenbytes2 = 0;
+ char bytebuffer2[BUFFER_SIZE];
+ for (size_t i = 0; i != samplelen; ++i) {
+ size_t nwr = 0;
const int res = RecodeFromUnicode(CODES_UTF8, sampletext[i], bytebuffer2 + writtenbytes2, BUFFER_SIZE - writtenbytes2, nwr);
- UNIT_ASSERT_VALUES_EQUAL(res, int(RECODE_OK));
- writtenbytes2 += nwr;
- UNIT_ASSERT(BUFFER_SIZE > writtenbytes2);
- }
- UNIT_ASSERT_VALUES_EQUAL(TStringBuf(bytebuffer, writtenbytes), TStringBuf(bytebuffer2, writtenbytes2));
-
+ UNIT_ASSERT_VALUES_EQUAL(res, int(RECODE_OK));
+ writtenbytes2 += nwr;
+ UNIT_ASSERT(BUFFER_SIZE > writtenbytes2);
+ }
+ UNIT_ASSERT_VALUES_EQUAL(TStringBuf(bytebuffer, writtenbytes), TStringBuf(bytebuffer2, writtenbytes2));
+
wchar32 charbuffer[BUFFER_SIZE];
size_t readbytes = 0;
size_t writtenchars = 0;
diff --git a/library/cpp/charset/recyr.hh b/library/cpp/charset/recyr.hh
index 9fcac30392..5ec8734bcf 100644
--- a/library/cpp/charset/recyr.hh
+++ b/library/cpp/charset/recyr.hh
@@ -30,8 +30,8 @@ inline RECODE_RESULT RecodeFromUnicode(ECharset to, const TCharType* in, char* o
inline RECODE_RESULT RecodeFromUnicode(ECharset to, wchar32 rune, char* out, size_t outSize, size_t& outWritten) {
return NCodepagePrivate::_recodeFromUnicode(to, rune, out, outSize, outWritten);
-}
-
+}
+
template <class TCharType>
inline RECODE_RESULT RecodeToUnicode(ECharset from, const char* in, TCharType* out, size_t inSize, size_t outSize) {
size_t inRead = 0;
@@ -101,36 +101,36 @@ inline RECODE_RESULT Recode(ECharset from, ECharset to, const char* in, char* ou
return Recode(from, to, in, out, inSize, outSize, inRead, outWritten);
}
-/**
- * Recode from one charset to another; throw an exception if conversion failed
+/**
+ * Recode from one charset to another; throw an exception if conversion failed
* @param[in] from the source character set
* @param[in] to the target character set
- * @param[in] in the input string buffer
- * @param[out] out the output string object if conversion was successful
- * @return false if conversion was not attempted (charsets were the same),
- * true if successful
- */
+ * @param[in] in the input string buffer
+ * @param[out] out the output string object if conversion was successful
+ * @return false if conversion was not attempted (charsets were the same),
+ * true if successful
+ */
inline bool Recode(ECharset from, ECharset to, const TStringBuf& in, TString& out) {
if (to == from)
- return false;
-
+ return false;
+
const size_t inSize = in.length();
const size_t outSize = SingleByteCodepage(to) ? inSize : 3 * inSize;
- out.clear(); // so we don't copy stuff around when resizing
+ out.clear(); // so we don't copy stuff around when resizing
out.ReserveAndResize(outSize);
-
+
size_t inRead = 0;
size_t outWritten = 0;
const RECODE_RESULT res = Recode(from, to, in.data(), out.begin(), inSize, outSize, inRead, outWritten);
Y_ENSURE(RECODE_OK == res, "Recode failed. ");
if (outWritten > outSize)
- ythrow yexception() << "Recode overrun the buffer: size="
+ ythrow yexception() << "Recode overrun the buffer: size="
<< outSize << " need=" << outWritten;
-
+
out.remove(outWritten);
- return true;
-}
-
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////////////
// TString -> TString //
///////////////////////////////////////////////////////////////////////////////////////
diff --git a/library/cpp/charset/recyr_int.hh b/library/cpp/charset/recyr_int.hh
index dcaecfc5e9..353af53305 100644
--- a/library/cpp/charset/recyr_int.hh
+++ b/library/cpp/charset/recyr_int.hh
@@ -172,7 +172,7 @@ namespace NCodepagePrivate {
inline RECODE_RESULT _recodeUnicodeToUTF8(wchar32 rune, char* out, size_t out_size, size_t& nwritten) {
return SafeWriteUTF8Char(rune, nwritten, (unsigned char*)out, out_size);
}
-
+
template <class TCharType, int Size = sizeof(TCharType)>
struct TCharTypeSwitch;
@@ -223,7 +223,7 @@ namespace NCodepagePrivate {
nwritten = 1;
return RECODE_OK;
}
-
+
inline RECODE_RESULT _rune2hex(wchar32 in, char* out, size_t out_size, size_t& out_writed) {
static const char hex_digs[] = "0123456789ABCDEF";
out_writed = 0;
@@ -301,17 +301,17 @@ namespace NCodepagePrivate {
return NCodepagePrivate::_recodeUnicodeToUTF8(in, out, in_size, out_size, in_readed, out_writed);
return NCodepagePrivate::_recodeUnicodeToSB(To, in, out, in_size, out_size, in_readed, out_writed);
- }
-
+ }
+
inline RECODE_RESULT _recodeFromUnicode(ECharset To, wchar32 rune, char* out, size_t out_size, size_t& nwritten) {
if (!ValidCodepage(To))
return RECODE_ERROR;
-
+
if (!NCodepagePrivate::NativeCodepage(To)) {
size_t nread = 0;
return NICONVPrivate::RecodeFromUnicodeNoThrow(To, &rune, out, 1, out_size, nread, nwritten);
}
-
+
if (To == CODES_UTF8)
return NCodepagePrivate::_recodeUnicodeToUTF8(rune, out, out_size, nwritten);
diff --git a/library/cpp/charset/wide.h b/library/cpp/charset/wide.h
index 2270773864..32d30e849e 100644
--- a/library/cpp/charset/wide.h
+++ b/library/cpp/charset/wide.h
@@ -16,15 +16,15 @@
//! converts text from unicode to yandex codepage
//! @attention destination buffer must be long enough to fit all characters of the text
//! @note @c dest buffer must fit at least @c len number of characters
-template <typename TCharType>
+template <typename TCharType>
inline size_t WideToChar(const TCharType* text, size_t len, char* dest, ECharset enc) {
Y_ASSERT(SingleByteCodepage(enc));
const char* start = dest;
const Encoder* const encoder = &EncoderByCharset(enc);
- const TCharType* const last = text + len;
- for (const TCharType* cur = text; cur != last; ++dest) {
+ const TCharType* const last = text + len;
+ for (const TCharType* cur = text; cur != last; ++dest) {
*dest = encoder->Tr(ReadSymbolAndAdvance(cur, last));
}
@@ -38,12 +38,12 @@ inline size_t WideToChar(const TCharType* text, size_t len, char* dest, ECharset
//! string using the @c strlen function and pass as the @c len parameter;
//! it does not make sense to create an additional version of this function because
//! it will call to @c strlen anyway in order to allocate destination buffer
-template <typename TCharType>
+template <typename TCharType>
inline void CharToWide(const char* text, size_t len, TCharType* dest, const CodePage& cp) {
const unsigned char* cur = reinterpret_cast<const unsigned char*>(text);
const unsigned char* const last = cur + len;
for (; cur != last; ++cur, ++dest) {
- *dest = static_cast<TCharType>(cp.unicode[*cur]); // static_cast is safe as no 1char codepage contains non-BMP symbols
+ *dest = static_cast<TCharType>(cp.unicode[*cur]); // static_cast is safe as no 1char codepage contains non-BMP symbols
}
}
@@ -55,21 +55,21 @@ namespace NDetail {
// Depending on template params, perform conversion of single-byte/multi-byte/utf8 string to/from wide string.
- template <typename TCharType>
+ template <typename TCharType>
inline TBasicStringBuf<TCharType> RecodeSingleByteChar(const TStringBuf src, TCharType* dst, const CodePage& cp) {
Y_ASSERT(cp.SingleByteCodepage());
::CharToWide(src.data(), src.size(), dst, cp);
return TBasicStringBuf<TCharType>(dst, src.size());
}
- template <typename TCharType>
+ template <typename TCharType>
inline TStringBuf RecodeSingleByteChar(const TBasicStringBuf<TCharType> src, char* dst, const CodePage& cp) {
Y_ASSERT(cp.SingleByteCodepage());
::WideToChar(src.data(), src.size(), dst, cp.CPEnum);
return TStringBuf(dst, src.size());
}
- template <typename TCharType>
+ template <typename TCharType>
inline TBasicStringBuf<TCharType> RecodeMultiByteChar(const TStringBuf src, TCharType* dst, ECharset encoding) {
Y_ASSERT(!NCodepagePrivate::NativeCodepage(encoding));
size_t read = 0;
@@ -78,7 +78,7 @@ namespace NDetail {
return TBasicStringBuf<TCharType>(dst, written);
}
- template <typename TCharType>
+ template <typename TCharType>
inline TStringBuf RecodeMultiByteChar(const TBasicStringBuf<TCharType> src, char* dst, ECharset encoding) {
Y_ASSERT(!NCodepagePrivate::NativeCodepage(encoding));
size_t read = 0;
@@ -87,7 +87,7 @@ namespace NDetail {
return TStringBuf(dst, written);
}
- template <typename TCharType>
+ template <typename TCharType>
inline TBasicStringBuf<TCharType> RecodeUtf8(const TStringBuf src, TCharType* dst) {
size_t len = 0;
if (!::UTF8ToWide(src.data(), src.size(), dst, len))
@@ -95,25 +95,25 @@ namespace NDetail {
return TBasicStringBuf<TCharType>(dst, len);
}
- template <typename TCharType>
+ template <typename TCharType>
inline TStringBuf RecodeUtf8(const TBasicStringBuf<TCharType> src, char* dst) {
size_t len = 0;
::WideToUTF8(src.data(), src.size(), dst, len);
return TStringBuf(dst, len);
}
- // Select one of re-coding methods from above, based on provided @encoding
-
- template <typename TCharFrom, typename TCharTo>
+ // Select one of re-coding methods from above, based on provided @encoding
+
+ template <typename TCharFrom, typename TCharTo>
TBasicStringBuf<TCharTo> Recode(const TBasicStringBuf<TCharFrom> src, TCharTo* dst, ECharset encoding) {
- if (encoding == CODES_UTF8)
- return RecodeUtf8(src, dst);
- else if (SingleByteCodepage(encoding))
- return RecodeSingleByteChar(src, dst, *CodePageByCharset(encoding));
- else
- return RecodeMultiByteChar(src, dst, encoding);
- }
-
+ if (encoding == CODES_UTF8)
+ return RecodeUtf8(src, dst);
+ else if (SingleByteCodepage(encoding))
+ return RecodeSingleByteChar(src, dst, *CodePageByCharset(encoding));
+ else
+ return RecodeMultiByteChar(src, dst, encoding);
+ }
+
}
template <typename TCharFrom>
diff --git a/library/cpp/charset/wide_ut.cpp b/library/cpp/charset/wide_ut.cpp
index 6bd754e0da..78947d51ba 100644
--- a/library/cpp/charset/wide_ut.cpp
+++ b/library/cpp/charset/wide_ut.cpp
@@ -151,7 +151,7 @@ public:
UNIT_TEST_SUITE_REGISTRATION(TConversionTest);
-// test conversions (char -> wchar32), (wchar32 -> char) and (wchar32 -> wchar16)
+// test conversions (char -> wchar32), (wchar32 -> char) and (wchar32 -> wchar16)
#define TEST_WCHAR32(sbuf, wbuf, enc) \
do { \
/* convert char to wchar32 */ \
@@ -169,7 +169,7 @@ UNIT_TEST_SUITE_REGISTRATION(TConversionTest);
UNIT_ASSERT_VALUES_EQUAL(sbuf, s1buf); \
UNIT_ASSERT_VALUES_EQUAL(wbuf, wstr2); \
} while (false)
-
+
void TConversionTest::TestCharToWide() {
TUtf16String w = CharToWide(YandexText, CODES_YANDEX);
@@ -236,7 +236,7 @@ void TConversionTest::TestRecodeIntoString() {
UNIT_ASSERT(sYandex.data() == sdata); // reserved buffer reused
UNIT_ASSERT(sYandex.data() == sres.data()); // same buffer
UNIT_ASSERT(sYandex.size() == sres.size()); // same size
- TEST_WCHAR32(sYandex, UnicodeText, CODES_YANDEX);
+ TEST_WCHAR32(sYandex, UnicodeText, CODES_YANDEX);
TUtf16String sUnicode;
sUnicode.reserve(YandexText.size() * 4);
@@ -254,7 +254,7 @@ void TConversionTest::TestRecodeIntoString() {
UNIT_ASSERT(sUtf8.capacity() > scap); // increased buffer capacity (supplied was too small)
UNIT_ASSERT(sUtf8.data() == sres.data()); // same buffer
UNIT_ASSERT(sUtf8.size() == sres.size()); // same size
- TEST_WCHAR32(sUtf8, UnicodeText, CODES_UTF8);
+ TEST_WCHAR32(sUtf8, UnicodeText, CODES_UTF8);
sUnicode.clear();
wdata = sUnicode.data();
@@ -336,11 +336,11 @@ void TConversionTest::TestRecodeAppend() {
}
}
-template <>
+template <>
void Out<RECODE_RESULT>(IOutputStream& out, RECODE_RESULT val) {
- out << int(val);
-}
-
+ out << int(val);
+}
+
void TConversionTest::TestRecode() {
for (int c = 0; c != CODES_MAX; ++c) {
ECharset enc = static_cast<ECharset>(c);
@@ -367,11 +367,11 @@ void TConversionTest::TestRecode() {
res = RecodeFromUnicode(enc, &wch, &rch, 1, 1, read, written);
UNIT_ASSERT(res == RECODE_OK);
- char rch2 = 0;
- UNIT_ASSERT_VALUES_EQUAL(RECODE_OK, RecodeFromUnicode(enc, wch, &rch2, 1, written));
- UNIT_ASSERT_VALUES_EQUAL(size_t(1), written);
- UNIT_ASSERT_VALUES_EQUAL(rch2, rch);
-
+ char rch2 = 0;
+ UNIT_ASSERT_VALUES_EQUAL(RECODE_OK, RecodeFromUnicode(enc, wch, &rch2, 1, written));
+ UNIT_ASSERT_VALUES_EQUAL(size_t(1), written);
+ UNIT_ASSERT_VALUES_EQUAL(rch2, rch);
+
if (hash.contains(rch)) { // there are some stupid encodings with duplicate characters
continue;
} else {
diff --git a/library/cpp/compproto/lib.cpp b/library/cpp/compproto/lib.cpp
index 0cf68d0295..dd23e5aa11 100644
--- a/library/cpp/compproto/lib.cpp
+++ b/library/cpp/compproto/lib.cpp
@@ -1,4 +1,4 @@
-#include "bit.h"
-#include "compressor.h"
-#include "huff.h"
-#include "metainfo.h"
+#include "bit.h"
+#include "compressor.h"
+#include "huff.h"
+#include "metainfo.h"
diff --git a/library/cpp/compproto/ya.make b/library/cpp/compproto/ya.make
index f6b429e70b..60d5cfa08d 100644
--- a/library/cpp/compproto/ya.make
+++ b/library/cpp/compproto/ya.make
@@ -7,7 +7,7 @@ SRCS(
compressor.h
huff.h
metainfo.h
- lib.cpp
-)
-
+ lib.cpp
+)
+
END()
diff --git a/library/cpp/containers/compact_vector/compact_vector_ut.cpp b/library/cpp/containers/compact_vector/compact_vector_ut.cpp
index 9eaffb4ce5..7d413d6575 100644
--- a/library/cpp/containers/compact_vector/compact_vector_ut.cpp
+++ b/library/cpp/containers/compact_vector/compact_vector_ut.cpp
@@ -26,21 +26,21 @@ Y_UNIT_TEST_SUITE(TCompactVectorTest) {
vector.Insert(vector.Begin(), 99);
- UNIT_ASSERT_VALUES_EQUAL(11u, vector.Size());
- UNIT_ASSERT_VALUES_EQUAL(99u, vector[0]);
+ UNIT_ASSERT_VALUES_EQUAL(11u, vector.Size());
+ UNIT_ASSERT_VALUES_EQUAL(99u, vector[0]);
for (ui32 i = 0; i < 10; ++i) {
UNIT_ASSERT_VALUES_EQUAL(i + 2, vector[i + 1]);
}
vector.Insert(vector.Begin() + 3, 77);
- UNIT_ASSERT_VALUES_EQUAL(12u, vector.Size());
- UNIT_ASSERT_VALUES_EQUAL(99u, vector[0]);
- UNIT_ASSERT_VALUES_EQUAL(2u, vector[1]);
- UNIT_ASSERT_VALUES_EQUAL(3u, vector[2]);
- UNIT_ASSERT_VALUES_EQUAL(77u, vector[3]);
- UNIT_ASSERT_VALUES_EQUAL(4u, vector[4]);
- UNIT_ASSERT_VALUES_EQUAL(5u, vector[5]);
- UNIT_ASSERT_VALUES_EQUAL(11u, vector[11]);
+ UNIT_ASSERT_VALUES_EQUAL(12u, vector.Size());
+ UNIT_ASSERT_VALUES_EQUAL(99u, vector[0]);
+ UNIT_ASSERT_VALUES_EQUAL(2u, vector[1]);
+ UNIT_ASSERT_VALUES_EQUAL(3u, vector[2]);
+ UNIT_ASSERT_VALUES_EQUAL(77u, vector[3]);
+ UNIT_ASSERT_VALUES_EQUAL(4u, vector[4]);
+ UNIT_ASSERT_VALUES_EQUAL(5u, vector[5]);
+ UNIT_ASSERT_VALUES_EQUAL(11u, vector[11]);
}
}
diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp
index ef89065155..74bee09b5d 100644
--- a/library/cpp/containers/comptrie/comptrie_ut.cpp
+++ b/library/cpp/containers/comptrie/comptrie_ut.cpp
@@ -870,13 +870,13 @@ void TCompactTrieTest::TestMergeFromFile() {
}
TCompactTrie<> trie(TBlob::FromFileSingleThreaded(GetSystemTempDir() + "/TCompactTrieTest-TestMerge-res"));
- UNIT_ASSERT_VALUES_EQUAL(12u, trie.Get("ru.yandex"));
- UNIT_ASSERT_VALUES_EQUAL(13u, trie.Get("ru.google"));
- UNIT_ASSERT_VALUES_EQUAL(14u, trie.Get("ru.mail"));
- UNIT_ASSERT_VALUES_EQUAL(22u, trie.Get("org.kernel"));
- UNIT_ASSERT_VALUES_EQUAL(112u, trie.Get("com.yandex"));
- UNIT_ASSERT_VALUES_EQUAL(113u, trie.Get("com.google"));
- UNIT_ASSERT_VALUES_EQUAL(114u, trie.Get("com.yahoo"));
+ UNIT_ASSERT_VALUES_EQUAL(12u, trie.Get("ru.yandex"));
+ UNIT_ASSERT_VALUES_EQUAL(13u, trie.Get("ru.google"));
+ UNIT_ASSERT_VALUES_EQUAL(14u, trie.Get("ru.mail"));
+ UNIT_ASSERT_VALUES_EQUAL(22u, trie.Get("org.kernel"));
+ UNIT_ASSERT_VALUES_EQUAL(112u, trie.Get("com.yandex"));
+ UNIT_ASSERT_VALUES_EQUAL(113u, trie.Get("com.google"));
+ UNIT_ASSERT_VALUES_EQUAL(114u, trie.Get("com.yahoo"));
unlink((GetSystemTempDir() + "/TCompactTrieTest-TestMerge-res").data());
unlink((GetSystemTempDir() + "/TCompactTrieTest-TestMerge-com").data());
diff --git a/library/cpp/deprecated/accessors/accessors_ut.cpp b/library/cpp/deprecated/accessors/accessors_ut.cpp
index 5fe5788189..a9bdc9fcc4 100644
--- a/library/cpp/deprecated/accessors/accessors_ut.cpp
+++ b/library/cpp/deprecated/accessors/accessors_ut.cpp
@@ -17,7 +17,7 @@ private:
void TestRead(const T& t, const char* comm) {
const char* beg = (const char*)NAccessors::Begin(t);
const char* end = (const char*)NAccessors::End(t);
- long sz = NAccessors::Size(t) * sizeof(typename TMemoryTraits<T>::TElementType);
+ long sz = NAccessors::Size(t) * sizeof(typename TMemoryTraits<T>::TElementType);
UNIT_ASSERT_VALUES_EQUAL_C(end - beg, sz, comm);
}
diff --git a/library/cpp/deprecated/split/split_iterator.h b/library/cpp/deprecated/split/split_iterator.h
index e2a4847889..0eacc29228 100644
--- a/library/cpp/deprecated/split/split_iterator.h
+++ b/library/cpp/deprecated/split/split_iterator.h
@@ -7,7 +7,7 @@
#include <util/system/yassert.h>
#include <util/system/defaults.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/strbuf.h>
#include <util/generic/string.h>
#include <util/generic/vector.h>
#include <util/generic/yexception.h>
@@ -277,13 +277,13 @@ public:
return Split.Next(Pos);
}
- TStringBuf NextTok() {
- if (Eof())
- return TStringBuf();
- TSizeTRegion region = Next();
- return TStringBuf(Split.Str + region.Begin, region.End - region.Begin);
- }
-
+ TStringBuf NextTok() {
+ if (Eof())
+ return TStringBuf();
+ TSizeTRegion region = Next();
+ return TStringBuf(Split.Str + region.Begin, region.End - region.Begin);
+ }
+
const TString& NextString() {
if (!CurrentStroka)
CurrentStroka = new TString();
diff --git a/library/cpp/digest/md5/md5.h b/library/cpp/digest/md5/md5.h
index 8930805b78..2c17aa0518 100644
--- a/library/cpp/digest/md5/md5.h
+++ b/library/cpp/digest/md5/md5.h
@@ -6,10 +6,10 @@
class IInputStream;
class MD5 {
-public:
- MD5() {
- Init();
- }
+public:
+ MD5() {
+ Init();
+ }
void Init();
@@ -66,7 +66,7 @@ public:
static bool IsMD5(TStringBuf data);
static bool IsMD5(const TArrayRef<const ui8>& data);
-private:
+private:
void UpdatePart(TArrayRef<const ui8> data);
private:
diff --git a/library/cpp/execprofile/profile.cpp b/library/cpp/execprofile/profile.cpp
index 9c42114106..d05de20203 100644
--- a/library/cpp/execprofile/profile.cpp
+++ b/library/cpp/execprofile/profile.cpp
@@ -7,11 +7,11 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
-#if defined(_darwin_)
-#include <sys/ucontext.h>
-#else
+#if defined(_darwin_)
+#include <sys/ucontext.h>
+#else
#include <ucontext.h>
-#endif
+#endif
#include <dlfcn.h>
#include <util/system/platform.h>
@@ -186,18 +186,18 @@ private:
#else
return (void*)mctx->gregs[REG_EIP];
#endif
-#elif defined _darwin_
+#elif defined _darwin_
#if defined _64_
#if defined(_arm_)
return (void*)(*mctx)->__ss.__pc;
#else
- return (void*)(*mctx)->__ss.__rip;
+ return (void*)(*mctx)->__ss.__rip;
#endif
#else
#if defined(__IOS__)
return (void*)(*mctx)->__ss.__pc;
#else
- return (void*)(*mctx)->__ss.__eip;
+ return (void*)(*mctx)->__ss.__eip;
#endif
#endif
#endif
diff --git a/library/cpp/getopt/small/last_getopt.cpp b/library/cpp/getopt/small/last_getopt.cpp
index 510d089382..30669b2c5a 100644
--- a/library/cpp/getopt/small/last_getopt.cpp
+++ b/library/cpp/getopt/small/last_getopt.cpp
@@ -1,9 +1,9 @@
#include "last_getopt.h"
-namespace NLastGetopt {
+namespace NLastGetopt {
void PrintUsageAndExit(const TOptsParser* parser) {
parser->PrintUsage();
exit(0);
}
-
+
}
diff --git a/library/cpp/getopt/small/last_getopt.h b/library/cpp/getopt/small/last_getopt.h
index a338d2cc56..07687bc914 100644
--- a/library/cpp/getopt/small/last_getopt.h
+++ b/library/cpp/getopt/small/last_getopt.h
@@ -22,14 +22,14 @@ namespace NLastGetopt {
public:
using TContainer = Container;
using TValue = typename TContainer::value_type;
-
+
explicit TOptRangeSplitHandler(TContainer* target, const char elementsDelim, const char rangesDelim)
: Target(target)
, ElementsDelim(elementsDelim)
, RangesDelim(rangesDelim)
{
}
-
+
void HandleOpt(const TOptsParser* parser) override {
const TStringBuf curval(parser->CurValOrDef());
if (curval.IsInited()) {
@@ -54,7 +54,7 @@ namespace NLastGetopt {
TContainer* Target;
char ElementsDelim;
char RangesDelim;
- };
+ };
template <class Container>
struct TOptSplitHandler: public IOptHandler {
diff --git a/library/cpp/getopt/small/last_getopt_support.h b/library/cpp/getopt/small/last_getopt_support.h
index 7d8cdfba55..17bed3e614 100644
--- a/library/cpp/getopt/small/last_getopt_support.h
+++ b/library/cpp/getopt/small/last_getopt_support.h
@@ -36,13 +36,13 @@ namespace NLastGetopt {
class THandlerFunctor0
: public IOptHandler {
TpFunc Func_;
-
+
public:
THandlerFunctor0(TpFunc func)
: Func_(func)
{
}
-
+
void HandleOpt(const TOptsParser*) override {
Func_();
}
@@ -54,7 +54,7 @@ namespace NLastGetopt {
TpFunc Func_;
const TpArg Def_;
const bool HasDef_;
-
+
public:
THandlerFunctor1(TpFunc func)
: Func_(func)
@@ -73,7 +73,7 @@ namespace NLastGetopt {
void HandleOpt(const TOptsParser* parser) override;
};
-
+
template <typename TpFunc>
class THandlerFunctor1<TpFunc, const TOptsParser*>
: public IOptHandler {
@@ -84,7 +84,7 @@ namespace NLastGetopt {
: Func_(func)
{
}
-
+
void HandleOpt(const TOptsParser* parser) override {
Func_(parser);
}
@@ -105,7 +105,7 @@ namespace NLastGetopt {
*Target_ = val;
}
};
-
+
template <typename TpTarget, typename TpFunc, typename TpVal = TpTarget>
class TStoreMappedResultFunctor {
private:
diff --git a/library/cpp/getopt/small/opt.cpp b/library/cpp/getopt/small/opt.cpp
index 356439eb38..744501765c 100644
--- a/library/cpp/getopt/small/opt.cpp
+++ b/library/cpp/getopt/small/opt.cpp
@@ -27,13 +27,13 @@ void Opt::Init(int argc, char* argv[], const char* optString, const Ion* longOpt
TOpt* opt;
if ((unsigned)o->val < 0x80 && isalnum(o->val)) {
opt = &Opts_->CharOption(char(o->val));
- opt->AddLongName(o->name);
+ opt->AddLongName(o->name);
} else {
Opts_->AddLongOption(o->name);
opt = const_cast<TOpt*>(&Opts_->GetLongOption(o->name));
}
opt->HasArg_ = EHasArg(o->has_arg);
- opt->UserValue(o);
+ opt->UserValue(o);
}
Opts_->AllowSingleDashForLong_ = longOnly;
Opts_->AllowPlusForLong_ = true;
@@ -68,7 +68,7 @@ int Opt::Get(int* longOptionIndex) {
return EOF;
} else {
Arg = (char*)OptsParser_->CurVal();
- if (!OptsParser_->CurOpt()) {
+ if (!OptsParser_->CurOpt()) {
// possible if RETURN_IN_ORDER
return 1;
} else {
@@ -76,7 +76,7 @@ int Opt::Get(int* longOptionIndex) {
if (longOptionIndex) {
*longOptionIndex = int(ion - Ions_);
}
- char c = OptsParser_->CurOpt()->GetCharOr0();
+ char c = OptsParser_->CurOpt()->GetCharOr0();
return c != 0 ? c : ion->val;
}
}
@@ -89,7 +89,7 @@ int Opt::Get(int* longOptionIndex) {
}
void Opt::DummyHelp(IOutputStream& os) {
- Opts_->PrintUsage(GetProgramName(), os);
+ Opts_->PrintUsage(GetProgramName(), os);
}
int Opt::GetArgC() const {
diff --git a/library/cpp/getopt/small/opt.h b/library/cpp/getopt/small/opt.h
index 404965c0d7..ecb57439bc 100644
--- a/library/cpp/getopt/small/opt.h
+++ b/library/cpp/getopt/small/opt.h
@@ -129,7 +129,7 @@ int opt_get_number(int& argc, char* argv[]);
} \
break;
-#define OPTION_HANDLE(opt, handle) \
+#define OPTION_HANDLE(opt, handle) \
OPTION_HANDLE_BEGIN(opt) \
handle; \
OPTION_HANDLE_END
diff --git a/library/cpp/getopt/small/posix_getopt.cpp b/library/cpp/getopt/small/posix_getopt.cpp
index bbe89080a5..bd06f3499f 100644
--- a/library/cpp/getopt/small/posix_getopt.cpp
+++ b/library/cpp/getopt/small/posix_getopt.cpp
@@ -29,13 +29,13 @@ namespace NLastGetopt {
TOpt* opt;
if ((unsigned)o->val < 0x80 && isalnum(o->val)) {
opt = &Opts->CharOption(char(o->val));
- opt->AddLongName(o->name);
+ opt->AddLongName(o->name);
} else {
Opts->AddLongOption(o->name);
opt = const_cast<TOpt*>(&Opts->GetLongOption(o->name));
}
opt->HasArg_ = EHasArg(o->has_arg);
- opt->UserValue(o->flag);
+ opt->UserValue(o->flag);
}
OptsParser.Reset(new TOptsParser(&*Opts, argc, (const char**)argv));
diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp
index fcdd8dcbf1..c99a1d053d 100644
--- a/library/cpp/getopt/ut/last_getopt_ut.cpp
+++ b/library/cpp/getopt/ut/last_getopt_ut.cpp
@@ -50,35 +50,35 @@ struct TOptsParserTester {
void AcceptOption() {
Accept();
- UNIT_ASSERT(!!Parser_->CurOpt());
+ UNIT_ASSERT(!!Parser_->CurOpt());
}
void AcceptOption(char c) {
AcceptOption();
- UNIT_ASSERT(Parser_->CurOpt()->CharIs(c));
+ UNIT_ASSERT(Parser_->CurOpt()->CharIs(c));
}
void AcceptOption(const TString& optName) {
AcceptOption();
- UNIT_ASSERT(Parser_->CurOpt()->NameIs(optName));
+ UNIT_ASSERT(Parser_->CurOpt()->NameIs(optName));
}
template <typename TOpt>
void AcceptOptionWithValue(TOpt optName, const TString& value) {
AcceptOption(optName);
- UNIT_ASSERT_VALUES_EQUAL_C(value, Parser_->CurValStr(), "; option " << optName);
+ UNIT_ASSERT_VALUES_EQUAL_C(value, Parser_->CurValStr(), "; option " << optName);
}
template <typename TOpt>
void AcceptOptionWithoutValue(TOpt optName) {
AcceptOption(optName);
- UNIT_ASSERT_C(!Parser_->CurVal(), ": opt " << optName << " must have no param");
+ UNIT_ASSERT_C(!Parser_->CurVal(), ": opt " << optName << " must have no param");
}
void AcceptFreeArgInOrder(const TString& expected) {
Accept();
- UNIT_ASSERT(!Parser_->CurOpt());
- UNIT_ASSERT_VALUES_EQUAL(expected, Parser_->CurValStr());
+ UNIT_ASSERT(!Parser_->CurOpt());
+ UNIT_ASSERT_VALUES_EQUAL(expected, Parser_->CurValStr());
}
size_t Pos_;
@@ -159,7 +159,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) {
UNIT_ASSERT(r.Has('l'));
UNIT_ASSERT(!r.Has('h'));
- UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgs().size());
+ UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgs().size());
UNIT_ASSERT_VALUES_EQUAL(2u, r.GetFreeArgCount());
UNIT_ASSERT_VALUES_EQUAL("/etc", r.GetFreeArgs()[0]);
UNIT_ASSERT_VALUES_EQUAL("/tmp/etc", r.GetFreeArgs()[1]);
@@ -372,7 +372,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) {
tester.AcceptEndOfOptions();
- UNIT_ASSERT_VALUES_EQUAL(1u, tester.Parser_->Pos_);
+ UNIT_ASSERT_VALUES_EQUAL(1u, tester.Parser_->Pos_);
}
Y_UNIT_TEST(TestExpectedUnknownCharOption) {
@@ -451,7 +451,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) {
UNIT_ASSERT_VALUES_EQUAL(42, a);
UNIT_ASSERT_VALUES_EQUAL(0, b);
UNIT_ASSERT(e == REQUIRED_ARGUMENT);
- UNIT_ASSERT_VALUES_EQUAL(12345u, c);
+ UNIT_ASSERT_VALUES_EQUAL(12345u, c);
}
Y_UNIT_TEST(TestSetFlag) {
@@ -519,61 +519,61 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) {
Y_UNIT_TEST(TestRequiredOpts) {
TOptsNoDefault opts;
- TOpt& opt_d = opts.AddCharOption('d');
-
- // test 'not required'
- // makes sure that the problem will only be in 'required'
+ TOpt& opt_d = opts.AddCharOption('d');
+
+ // test 'not required'
+ // makes sure that the problem will only be in 'required'
TOptsParseResultTestWrapper r1(&opts, V({"cmd"}));
-
- // test 'required'
- opt_d.Required();
+
+ // test 'required'
+ opt_d.Required();
UNIT_ASSERT_EXCEPTION(
TOptsParseResultTestWrapper(&opts, V({"cmd"})),
TUsageException);
-
+
TOptsParseResultTestWrapper r3(&opts, V({"cmd", "-d11"}));
- UNIT_ASSERT_VALUES_EQUAL("11", r3.Get('d'));
- }
-
+ UNIT_ASSERT_VALUES_EQUAL("11", r3.Get('d'));
+ }
+
class HandlerStoreTrue {
bool* Flag;
- public:
+ public:
HandlerStoreTrue(bool* flag)
- : Flag(flag)
+ : Flag(flag)
{
}
void operator()() {
- *Flag = true;
- }
- };
+ *Flag = true;
+ }
+ };
Y_UNIT_TEST(TestHandlers) {
- {
+ {
TOptsNoDefault opts;
- bool flag = false;
- opts.AddLongOption("flag").Handler0(HandlerStoreTrue(&flag)).NoArgument();
+ bool flag = false;
+ opts.AddLongOption("flag").Handler0(HandlerStoreTrue(&flag)).NoArgument();
TOptsParseResultTestWrapper r(&opts, V({"cmd", "--flag"}));
- UNIT_ASSERT(flag);
- }
- {
+ UNIT_ASSERT(flag);
+ }
+ {
TOptsNoDefault opts;
- unsigned uval = 5;
- double fval = 0.0;
- opts.AddLongOption("flag1").RequiredArgument().StoreResult(&uval);
- opts.AddLongOption("flag2").RequiredArgument().StoreResultT<int>(&uval);
+ unsigned uval = 5;
+ double fval = 0.0;
+ opts.AddLongOption("flag1").RequiredArgument().StoreResult(&uval);
+ opts.AddLongOption("flag2").RequiredArgument().StoreResultT<int>(&uval);
opts.AddLongOption("flag3").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))fabs);
opts.AddLongOption("flag4").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))sqrt);
UNIT_ASSERT_EXCEPTION(
TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})),
yexception);
- UNIT_ASSERT_VALUES_EQUAL(uval, 5u);
- UNIT_ASSERT_VALUES_EQUAL(fval, 2.0);
+ UNIT_ASSERT_VALUES_EQUAL(uval, 5u);
+ UNIT_ASSERT_VALUES_EQUAL(fval, 2.0);
TOptsParseResultTestWrapper r1(&opts, V({"cmd", "--flag4", "9.0", "--flag2", "-1"}));
- UNIT_ASSERT_VALUES_EQUAL(uval, Max<unsigned>());
- UNIT_ASSERT_VALUES_EQUAL(fval, 3.0);
- }
- }
-
+ UNIT_ASSERT_VALUES_EQUAL(uval, Max<unsigned>());
+ UNIT_ASSERT_VALUES_EQUAL(fval, 3.0);
+ }
+ }
+
Y_UNIT_TEST(TestTitleAndPrintUsage) {
TOpts opts;
const char* prog = "my_program";
diff --git a/library/cpp/getopt/ut/opt2_ut.cpp b/library/cpp/getopt/ut/opt2_ut.cpp
index 9322f24e51..0e7464747c 100644
--- a/library/cpp/getopt/ut/opt2_ut.cpp
+++ b/library/cpp/getopt/ut/opt2_ut.cpp
@@ -35,7 +35,7 @@ Y_UNIT_TEST_SUITE(Opt2Test) {
UNIT_ASSERT_VALUES_EQUAL(8, d);
UNIT_ASSERT_VALUES_EQUAL((void*)edef, e);
- UNIT_ASSERT_VALUES_EQUAL(2u, opt.Pos.size());
+ UNIT_ASSERT_VALUES_EQUAL(2u, opt.Pos.size());
UNIT_ASSERT_STRINGS_EQUAL("zz", opt.Pos.at(0));
UNIT_ASSERT_VALUES_EQUAL((void*)argv[2], opt.Pos.at(0));
UNIT_ASSERT_STRINGS_EQUAL("ww", opt.Pos.at(1));
diff --git a/library/cpp/html/pcdata/pcdata.cpp b/library/cpp/html/pcdata/pcdata.cpp
index 79a87401cf..740c240fd2 100644
--- a/library/cpp/html/pcdata/pcdata.cpp
+++ b/library/cpp/html/pcdata/pcdata.cpp
@@ -14,8 +14,8 @@ static void EncodeHtmlPcdataAppendInternal(const TStringBuf str, TString& strout
strout.AppendNoAlias(s, next - s);
s = next;
- if (s == e)
- break;
+ if (s == e)
+ break;
switch (*s) {
case '\"':
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp
index 48594a79da..e523350b80 100644
--- a/library/cpp/string_utils/quote/quote.cpp
+++ b/library/cpp/string_utils/quote/quote.cpp
@@ -37,13 +37,13 @@ namespace {
static inline char x2c(TStringBuf& x) {
if (!IsAsciiHex((ui8)x[0]) || !IsAsciiHex((ui8)x[1]))
- return '%';
- ui8 c = 0;
-
+ return '%';
+ ui8 c = 0;
+
GETSBXC;
GETSBXC;
- return c;
- }
+ return c;
+ }
};
class TFromHexLenLimited {
@@ -242,13 +242,13 @@ TString CGIUnescapeRet(const TStringBuf from) {
return to;
}
-char* UrlUnescape(char* to, TStringBuf from) {
+char* UrlUnescape(char* to, TStringBuf from) {
while (!from.empty()) {
- char ch = from[0];
+ char ch = from[0];
from.Skip(1);
- if ('%' == ch && 2 <= from.length())
- ch = TFromHexZeroTerm::x2c(from);
- *to++ = ch;
+ if ('%' == ch && 2 <= from.length())
+ ch = TFromHexZeroTerm::x2c(from);
+ *to++ = ch;
}
*to = 0;
diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h
index 527668defb..3b7221154e 100644
--- a/library/cpp/string_utils/quote/quote.h
+++ b/library/cpp/string_utils/quote/quote.h
@@ -12,14 +12,14 @@ char* CGIEscape(char* to, const char* from);
char* CGIEscape(char* to, const char* from, size_t len);
inline char* CGIEscape(char* to, const TStringBuf from) {
return CGIEscape(to, from.data(), from.size());
-}
+}
void CGIEscape(TString& url);
TString CGIEscapeRet(const TStringBuf url);
TString& AppendCgiEscaped(const TStringBuf value, TString& to);
inline TStringBuf CgiEscapeBuf(char* to, const TStringBuf from) {
return TStringBuf(to, CGIEscape(to, from.data(), from.size()));
-}
+}
inline TStringBuf CgiEscape(void* tmp, const TStringBuf s) {
return CgiEscapeBuf(static_cast<char*>(tmp), s);
}
@@ -35,7 +35,7 @@ TString CGIUnescapeRet(const TStringBuf from);
inline TStringBuf CgiUnescapeBuf(char* to, const TStringBuf from) {
return TStringBuf(to, CGIUnescape(to, from.data(), from.size()));
-}
+}
inline TStringBuf CgiUnescape(void* tmp, const TStringBuf s) {
return CgiUnescapeBuf(static_cast<char*>(tmp), s);
}
@@ -58,7 +58,7 @@ TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false);
//UrlUnescape:
// '+' is NOT converted to space!
// %xx converted to bytes, other characters are copied unchanged.
-char* UrlUnescape(char* to, TStringBuf from);
+char* UrlUnescape(char* to, TStringBuf from);
void UrlUnescape(TString& url);
TString UrlUnescapeRet(const TStringBuf from);
diff --git a/library/cpp/string_utils/scan/scan.h b/library/cpp/string_utils/scan/scan.h
index 5711bafeab..703db54321 100644
--- a/library/cpp/string_utils/scan/scan.h
+++ b/library/cpp/string_utils/scan/scan.h
@@ -4,19 +4,19 @@
template <bool addAll, char sep, char sepKeyVal, class F>
static inline void ScanKeyValue(TStringBuf s, F&& f) {
- TStringBuf key, val;
+ TStringBuf key, val;
while (!s.empty()) {
val = s.NextTok(sep);
if (val.empty()) {
- continue; // && case
+ continue; // && case
}
key = val.NextTok(sepKeyVal);
if (addAll || val.IsInited()) {
- f(key, val); // includes empty keys
+ f(key, val); // includes empty keys
}
}
}
diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp
index 31fb932a4d..85f4ac5d69 100644
--- a/library/cpp/string_utils/url/url.cpp
+++ b/library/cpp/string_utils/url/url.cpp
@@ -364,18 +364,18 @@ static inline int Unescape(char* str) {
size_t NormalizeUrlName(char* dest, const TStringBuf source, size_t dest_size) {
if (source.empty() || source[0] == '?')
return strlcpy(dest, "/", dest_size);
- size_t len = Min(dest_size - 1, source.length());
- memcpy(dest, source.data(), len);
- dest[len] = 0;
+ size_t len = Min(dest_size - 1, source.length());
+ memcpy(dest, source.data(), len);
+ dest[len] = 0;
len -= Unescape(dest);
strlwr(dest);
return len;
}
size_t NormalizeHostName(char* dest, const TStringBuf source, size_t dest_size, ui16 defport) {
- size_t len = Min(dest_size - 1, source.length());
- memcpy(dest, source.data(), len);
- dest[len] = 0;
+ size_t len = Min(dest_size - 1, source.length());
+ memcpy(dest, source.data(), len);
+ dest[len] = 0;
char buf[8] = ":";
size_t buflen = 1 + ToString(defport, buf + 1, sizeof(buf) - 2);
buf[buflen] = '\0';
diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h
index 3535aaeda2..44517a0092 100644
--- a/library/cpp/testing/unittest/registar.h
+++ b/library/cpp/testing/unittest/registar.h
@@ -701,7 +701,7 @@ public: \
return false;
}
- }
+ }
//values
#define UNIT_ASSERT_VALUES_EQUAL_IMPL(A, B, C, EQflag, EQstr, NEQstr) \
@@ -721,14 +721,14 @@ public: \
} \
} while (false)
-#define UNIT_ASSERT_VALUES_EQUAL_C(A, B, C) \
- UNIT_ASSERT_VALUES_EQUAL_IMPL(A, B, C, true, "==", "!=")
+#define UNIT_ASSERT_VALUES_EQUAL_C(A, B, C) \
+ UNIT_ASSERT_VALUES_EQUAL_IMPL(A, B, C, true, "==", "!=")
+
+#define UNIT_ASSERT_VALUES_UNEQUAL_C(A, B, C) \
+ UNIT_ASSERT_VALUES_EQUAL_IMPL(A, B, C, false, "!=", "==")
-#define UNIT_ASSERT_VALUES_UNEQUAL_C(A, B, C) \
- UNIT_ASSERT_VALUES_EQUAL_IMPL(A, B, C, false, "!=", "==")
-
#define UNIT_ASSERT_VALUES_EQUAL(A, B) UNIT_ASSERT_VALUES_EQUAL_C(A, B, "")
-#define UNIT_ASSERT_VALUES_UNEQUAL(A, B) UNIT_ASSERT_VALUES_UNEQUAL_C(A, B, "")
+#define UNIT_ASSERT_VALUES_UNEQUAL(A, B) UNIT_ASSERT_VALUES_UNEQUAL_C(A, B, "")
// Checks that test will fail while executing given expression
// Macro for using in unitests for ut helpers
diff --git a/library/cpp/uri/assign.cpp b/library/cpp/uri/assign.cpp
index ff29afc10d..ae9125c727 100644
--- a/library/cpp/uri/assign.cpp
+++ b/library/cpp/uri/assign.cpp
@@ -1,16 +1,16 @@
-#include "uri.h"
-#include "parse.h"
+#include "uri.h"
+#include "parse.h"
+
+#include <contrib/libs/libidn/idna.h>
-#include <contrib/libs/libidn/idna.h>
-
#include <library/cpp/charset/recyr.hh>
-#include <util/charset/wide.h>
-#include <util/memory/tempbuf.h>
-#include <util/string/cast.h>
-#include <util/system/yassert.h>
+#include <util/charset/wide.h>
+#include <util/memory/tempbuf.h>
+#include <util/string/cast.h>
+#include <util/system/yassert.h>
#include <util/system/sys_alloc.h>
-namespace NUri {
+namespace NUri {
TMallocPtr<char> TUri::IDNToAscii(const wchar32* idna) {
// XXX: don't use punycode_encode directly as it doesn't include
// proper stringprep and splitting on dot-equivalent characters
@@ -24,21 +24,21 @@ namespace NUri {
TMallocPtr<char> TUri::IDNToAscii(const TStringBuf& host, ECharset enc) {
TTempBuf buf(sizeof(wchar32) * (1 + host.length()));
wchar32* wbuf = reinterpret_cast<wchar32*>(buf.Data());
-
+
const size_t written = NDetail::NBaseOps::Recode(host, wbuf, enc).length();
wbuf[written] = 0;
-
+
return IDNToAscii(wbuf);
}
-
+
TStringBuf TUri::HostToAscii(TStringBuf host, TMallocPtr<char>& buf, bool hasExtended, bool allowIDN, ECharset enc) {
TStringBuf outhost; // store the result here before returning it, to get RVO
-
+
size_t buflen = 0;
-
+
if (hasExtended && !allowIDN)
return outhost; // definitely can't convert
-
+
// charset-recode: RFC 3986, 3.2.2, requires percent-encoded non-ASCII
// chars in reg-name to be UTF-8 so convert to UTF-8 prior to decoding
const bool recoding = CODES_UTF8 != enc && hasExtended;
@@ -50,7 +50,7 @@ namespace NUri {
return outhost;
host = TStringBuf(buf.Get(), nwr);
}
-
+
// percent-decode
if (0 == buflen) {
buflen = host.length();
@@ -64,22 +64,22 @@ namespace NUri {
// check again
if (hasExtended && !allowIDN)
- return outhost;
-
+ return outhost;
+
host = out.Str();
-
+
// convert to punycode if needed
if (!hasExtended) {
outhost = host;
return outhost;
}
-
+
TMallocPtr<char> puny;
try {
puny = IDNToAscii(host);
} catch (const yexception& /* exc */) {
}
-
+
if (!puny) {
// XXX: try user charset unless UTF8 or converted to it
if (CODES_UTF8 == enc || recoding)
@@ -92,50 +92,50 @@ namespace NUri {
if (!puny)
return outhost;
}
-
+
buf = puny;
outhost = buf.Get();
-
+
return outhost;
- }
-
+ }
+
TStringBuf TUri::HostToAscii(const TStringBuf& host, TMallocPtr<char>& buf, bool allowIDN, ECharset enc) {
// find what we have
long haveFlags = 0;
for (size_t i = 0; i != host.length(); ++i)
haveFlags |= TEncoder::GetFlags(host[i]).FeatFlags;
-
+
// interested in encoded characters or (if IDN is allowed) extended ascii
TStringBuf outhost;
const bool haveExtended = haveFlags & FeatureEncodeExtendedASCII;
-
+
if (!haveExtended || allowIDN) {
if (!haveExtended && 0 == (haveFlags & FeatureDecodeANY))
outhost = host;
else
outhost = HostToAscii(host, buf, haveExtended, allowIDN, enc);
}
-
+
return outhost;
}
-
+
static inline bool AppendField(TMemoryWriteBuffer& out, TField::EField fld, const TStringBuf& val, long flags) {
if (val.empty())
return false;
if (flags & TFeature::FeaturesAllEncoder)
TUri::ReEncodeField(out, val, fld, flags);
- else
+ else
out << val;
return true;
- }
-
+ }
+
TState::EParsed TUri::AssignImpl(const TParser& parser, TScheme::EKind defscheme) {
Clear();
-
+
TState::EParsed ret = parser.State;
if (ParsedBadFormat <= ret)
return ret;
-
+
const TSection& scheme = parser.Get(FieldScheme);
const TSchemeInfo& schemeInfo = SetSchemeImpl(parser.Scheme);
@@ -154,9 +154,9 @@ namespace NUri {
long flags = parser.Flags.Allow;
if (convertIDN)
flags |= FeatureAllowHostIDN | FeatureCheckHost;
-
+
// process non-ASCII host for punycode
-
+
TMallocPtr<char> hostptr;
TStringBuf hostascii; // empty: use host field; non-empty: ascii
bool hostConverted = false; // hostascii is empty or the original
@@ -164,13 +164,13 @@ namespace NUri {
if (host.IsSet() && !FldIsSet(FieldHost)) {
const bool allowIDN = (flags & FeatureAllowHostIDN);
const TStringBuf hostbuf = host.Get();
-
+
// if we know we have and allow extended-ASCII chars, no need to check further
if (allowIDN && (host.GetFlagsAllPlaintext() & FeatureEncodeExtendedASCII))
hostascii = HostToAscii(hostbuf, hostptr, true, true, parser.Enc);
else
hostascii = HostToAscii(hostbuf, hostptr, allowIDN, parser.Enc);
-
+
if (hostascii.empty())
ret = ParsedBadHost; // exists but cannot be converted
else if (hostbuf.data() != hostascii.data()) {
@@ -180,21 +180,21 @@ namespace NUri {
FldMarkSet(FieldHost); // so that we don't process host below
}
}
-
+
// add unprocessed fields
-
+
for (int idx = 0; idx < FieldUrlMAX; ++idx) {
const EField fld = EField(idx);
const TSection& section = parser.Get(fld);
if (section.IsSet() && !FldIsSet(fld))
buflen += 1 + section.EncodedLen(); // includes null
- }
+ }
if (0 == buflen) // no more sections set?
return ret;
-
+
// process #! fragments
// https://developers.google.com/webmasters/ajax-crawling/docs/specification
-
+
static const TStringBuf escFragPrefix(TStringBuf("_escaped_fragment_="));
bool encHashBangFrag = false;
@@ -203,7 +203,7 @@ namespace NUri {
do {
if (FldIsSet(FieldFrag) || FldIsSet(FieldQuery))
break;
-
+
const TSection& frag = parser.Get(FieldFrag);
if (frag.IsSet()) {
if (0 == (parser.Flags & FeatureHashBangToEscapedFragment))
@@ -232,33 +232,33 @@ namespace NUri {
buflen -= escFragPrefix.length();
}
} while (false);
-
+
// now set all fields prior to validating
-
+
Alloc(buflen);
-
+
TMemoryWriteBuffer out(Buffer.data(), Buffer.size());
for (int idx = 0; idx < FieldUrlMAX; ++idx) {
const EField fld = EField(idx);
-
+
const TSection& section = parser.Get(fld);
if (!section.IsSet() || FldIsSet(fld))
continue;
-
+
if (FieldQuery == fld && encHashBangFrag)
continue;
-
+
if (FieldFrag == fld && qryEscapedFragment.IsInited())
continue;
char* beg = out.Buf();
TStringBuf val = section.Get();
long careFlags = section.GetFlagsEncode();
-
+
switch (fld) {
default:
break;
-
+
case FieldQuery:
if (qryEscapedFragment.IsInited()) {
const EField dstfld = FieldFrag; // that's where we will store
@@ -273,7 +273,7 @@ namespace NUri {
val = qryBeforeEscapedFragment;
}
break;
-
+
case FieldFrag:
if (encHashBangFrag) {
const EField dstfld = FieldQuery; // that's where we will store
@@ -289,7 +289,7 @@ namespace NUri {
}
break;
}
-
+
AppendField(out, fld, val, careFlags);
char* end = out.Buf();
@@ -300,7 +300,7 @@ namespace NUri {
Y_ASSERT(beg >= out.Beg());
out.SetPos(end);
}
-
+
FldSetNoDirty(fld, TStringBuf(beg, end));
// special character case
@@ -309,7 +309,7 @@ namespace NUri {
const long allowChars = parser.GetFieldFlags(fld) & checkChars;
if (checkChars != allowChars)
ret = ParsedBadFormat;
- }
+ }
out << '\0';
}
@@ -324,28 +324,28 @@ namespace NUri {
}
Buffer.Resize(out.Len());
-
+
if (GetScheme() == SchemeEmpty && SchemeEmpty != defscheme) {
if (SchemeUnknown == defscheme)
ret = ParsedBadScheme;
else
SetSchemeImpl(defscheme);
}
-
+
if (0 == (parser.Flags & FeatureAllowEmptyPath))
CheckMissingFields();
-
+
const TStringBuf& port = GetField(FieldPort);
if (!port.empty()) {
if (!TryFromString<ui16>(port, Port))
ret = ParsedBadPort;
- }
+ }
if (ParsedOK != ret)
return ret;
-
+
// run validity checks now that all fields are set
-
+
// check the host for DNS compliance
do {
if (0 == (flags & FeatureCheckHost))
@@ -363,28 +363,28 @@ namespace NUri {
} while (false);
return ret;
- }
-
+ }
+
TState::EParsed TUri::ParseImpl(const TStringBuf& url, const TParseFlags& flags, ui32 maxlen, TScheme::EKind defscheme, ECharset enc) {
Clear();
-
+
if (url.empty())
return ParsedEmpty;
if (maxlen > 0 && url.length() > maxlen)
return ParsedTooLong;
-
+
const TParser parser(flags, url, enc);
-
+
return AssignImpl(parser, defscheme);
}
TState::EParsed TUri::Parse(const TStringBuf& url, const TParseFlags& flags, const TStringBuf& url_base, ui32 maxlen, ECharset enc) {
const TParseFlags flags1 = flags.Exclude(FeatureNoRelPath);
TState::EParsed ret = ParseImpl(url, url_base.empty() ? flags : flags1, maxlen, SchemeEmpty, enc);
- if (ParsedOK != ret)
- return ret;
-
+ if (ParsedOK != ret)
+ return ret;
+
if (!url_base.empty() && !IsValidAbs()) {
TUri base;
ret = base.ParseImpl(url_base, flags, maxlen, SchemeEmpty, enc);
@@ -394,19 +394,19 @@ namespace NUri {
}
Rewrite();
- return ret;
+ return ret;
}
-
+
TState::EParsed TUri::Parse(const TStringBuf& url, const TUri& base, const TParseFlags& flags, ui32 maxlen, ECharset enc) {
const TState::EParsed ret = ParseImpl(url, flags, maxlen, SchemeEmpty, enc);
- if (ParsedOK != ret)
- return ret;
-
+ if (ParsedOK != ret)
+ return ret;
+
if (!IsValidAbs())
Merge(base, PathOperationFlag(flags));
-
+
Rewrite();
- return ret;
+ return ret;
}
TState::EParsed TUri::ParseAbsUri(const TStringBuf& url, const TParseFlags& flags, ui32 maxlen, TScheme::EKind defscheme, ECharset enc) {
@@ -414,12 +414,12 @@ namespace NUri {
url, flags | FeatureNoRelPath, maxlen, defscheme, enc);
if (ParsedOK != ret)
return ret;
-
+
if (IsNull(FlagHost))
return ParsedBadHost;
Rewrite();
return ParsedOK;
}
-
-}
+
+}
diff --git a/library/cpp/uri/common.cpp b/library/cpp/uri/common.cpp
index 3f91c34cad..05af1e57d1 100644
--- a/library/cpp/uri/common.cpp
+++ b/library/cpp/uri/common.cpp
@@ -1,11 +1,11 @@
-#include "common.h"
+#include "common.h"
-#include <util/generic/map.h>
+#include <util/generic/map.h>
#include <util/generic/singleton.h>
-namespace NUri {
+namespace NUri {
static_assert(TFeature::FeatureMAX <= sizeof(unsigned long) * 8, "expect TFeature::FeatureMAX <= sizeof(unsigned long) * 8");
-
+
const TSchemeInfo TSchemeInfo::Registry[] = {
TSchemeInfo(TScheme::SchemeEmpty, TStringBuf()), // scheme is empty and inited
TSchemeInfo(TScheme::SchemeHTTP, TStringBuf("http"), TField::FlagHost | TField::FlagPath, 80),
@@ -17,18 +17,18 @@ namespace NUri {
// add above
TSchemeInfo(TScheme::SchemeUnknown, TStringBuf()) // scheme is empty and uninited
};
-
+
namespace {
struct TLessNoCase {
bool operator()(const TStringBuf& lt, const TStringBuf& rt) const {
return 0 > CompareNoCase(lt, rt);
}
};
-
+
class TSchemeInfoMap {
typedef TMap<TStringBuf, TScheme::EKind, TLessNoCase> TdMap;
TdMap Map_;
-
+
public:
TSchemeInfoMap() {
for (int i = TScheme::SchemeEmpty; i < TScheme::SchemeUnknown; ++i) {
@@ -36,7 +36,7 @@ namespace NUri {
Map_.insert(std::make_pair(info.Str, info.Kind));
}
}
-
+
TScheme::EKind Get(const TStringBuf& scheme) const {
const TdMap::const_iterator it = Map_.find(scheme);
return Map_.end() == it ? TScheme::SchemeUnknown : it->second;
@@ -51,7 +51,7 @@ namespace NUri {
const TSchemeInfo& TSchemeInfo::Get(const TStringBuf& scheme) {
return Registry[TSchemeInfoMap::Instance().Get(scheme)];
- }
+ }
const char* ParsedStateToString(const TState::EParsed& t) {
switch (t) {
@@ -79,7 +79,7 @@ namespace NUri {
return "Parsed[Unknown]";
}
}
-
+
const char* FieldToString(const TField::EField& t) {
switch (t) {
case TField::FieldScheme:
diff --git a/library/cpp/uri/common.h b/library/cpp/uri/common.h
index de34fd897e..8025357763 100644
--- a/library/cpp/uri/common.h
+++ b/library/cpp/uri/common.h
@@ -1,10 +1,10 @@
#pragma once
-#include <util/stream/output.h>
-#include <util/system/compat.h>
+#include <util/stream/output.h>
+#include <util/system/compat.h>
#include <util/generic/strbuf.h>
-namespace NUri {
+namespace NUri {
namespace NEncode {
class TEncoder;
class TEncodeMapperBase;
@@ -14,13 +14,13 @@ namespace NUri {
namespace NParse {
class TRange;
}
-
+
class TParser;
-
+
struct TField {
#define FIELD_NAME(f) Field##f
#define FIELD_FLAG(f) Flag##f = 1U << FIELD_NAME(f)
-
+
enum EField {
FIELD_NAME(Scheme),
FIELD_NAME(User),
@@ -30,24 +30,24 @@ namespace NUri {
FIELD_NAME(Path),
FIELD_NAME(Query),
FIELD_NAME(Frag),
-
+
// add fields above
FieldUrlMAX,
// reset count so actual field offsets are not interrupted
FieldUrlLast = FieldUrlMAX - 1,
// add extra fields below
-
+
FIELD_NAME(HostAscii),
-
+
// add extra fields above
FieldAllMAX,
// add aliases below
-
+
FieldUsername = FieldUser,
FieldPassword = FieldPass,
FieldFragment = FieldFrag,
};
-
+
enum EFlags {
FIELD_FLAG(Scheme),
FIELD_FLAG(User),
@@ -70,11 +70,11 @@ namespace NUri {
FlagAll = FlagUrlFields, // obsolete, for backwards compatibility
FlagAllFields = FlagAllMAX - 1
};
-
-#undef FIELD_NAME
-#undef FIELD_FLAG
+
+#undef FIELD_NAME
+#undef FIELD_FLAG
};
-
+
struct TState {
enum EParsed {
ParsedOK = 0,
@@ -88,7 +88,7 @@ namespace NUri {
ParsedBadAuth,
ParsedBadScheme,
ParsedBadHost,
-
+
// add before this line
ParsedMAX
};
@@ -121,17 +121,17 @@ 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)
protected:
enum EBit {
//==============================
// Cases interpreted as errors:
//==============================
-
+
// allows authorization user/password in URL
FEATURE_NAME(AuthSupported),
-
+
// allows all known schemes in URL
FEATURE_NAME(SchemeKnown),
@@ -140,7 +140,7 @@ namespace NUri {
// allow opaque (RFC 2396) or rootless (RFC 3986) urls
FEATURE_NAME(AllowRootless),
-
+
//==============================
// Cases interpreted for processing (if required):
// (effects on result of Parse method)
@@ -149,70 +149,70 @@ namespace NUri {
// path needs normalization
// (simplification of directory tree: /../, /./, etc.
FEATURE_NAME(PathOperation),
-
+
// don't force empty path to "/"
FEATURE_NAME(AllowEmptyPath),
-
+
// in scheme and host segments:
// change upper case letters onto lower case ones
FEATURE_NAME(ToLower),
// decode unreserved symbols
FEATURE_NAME(DecodeUnreserved),
-
+
// legacy: decode standard symbols which may be safe for some fields
FEATURE_NAME(DecodeStandardExtra),
-
+
// decode symbols allowed (not necessarily safe to decode) only for a given field
// (do not use directly, instead use FeatureDecodeSafe mask below)
FEATURE_NAME(DecodeFieldAllowed),
-
+
// handling of spaces
FEATURE_NAME(EncodeSpace),
-
+
// in query segment: change escaped space to '+'
FEATURE_NAME(EncodeSpaceAsPlus),
-
+
// escape all string 'markup' symbols
FEATURE_NAME(EncodeForSQL),
-
+
// encoding of extended ascii symbols (8-bit)
FEATURE_NAME(EncodeExtendedASCII),
-
+
// decoding of extended ascii symbols (8-bit)
FEATURE_NAME(DecodeExtendedASCII),
-
+
// encoding of extended delimiter set
FEATURE_NAME(EncodeExtendedDelim),
-
+
// decoding of extended delimiter set
FEATURE_NAME(DecodeExtendedDelim),
-
+
// control characters [0x00 .. 0x20)
FEATURE_NAME(EncodeCntrl),
-
+
// raw percent character
FEATURE_NAME(EncodePercent),
-
+
// hash fragments
// https://developers.google.com/webmasters/ajax-crawling/docs/specification
// move and encode #! fragments to the query
FEATURE_NAME(HashBangToEscapedFragment),
// move and decode _escaped_fragment_ to the fragment
FEATURE_NAME(EscapedToHashBangFragment),
-
+
// reject absolute paths started by "/../"
FEATURE_NAME(PathDenyRootParent),
-
+
// paths started by "/../" - ignore head
FEATURE_NAME(PathStripRootParent),
-
+
// tries to fix errors (in particular, in fragment)
FEATURE_NAME(TryToFix),
// check host for DNS compliance
FEATURE_NAME(CheckHost),
-
+
// allow IDN hosts
// host is converted to punycode and stored in FieldHostAscii
// @note host contains characters in the charset of the document
@@ -221,47 +221,47 @@ namespace NUri {
// percent-decoding cannot be converted from UTF-8 to UCS-4,
// try to recode from the document charset (if not UTF-8)
FEATURE_NAME(AllowHostIDN),
-
+
// forces AllowHostIDN, but host is replaced with punycode
// forces CheckHost since this replacement is irreversible
FEATURE_NAME(ConvertHostIDN),
-
+
// robot interpreted network paths as BadFormat urls
FEATURE_NAME(DenyNetworkPath),
// robot interprets URLs without a host as BadFormat
FEATURE_NAME(RemoteOnly),
-
+
/* non-RFC use case:
- * 1. do not allow relative-path-only URIs when they can conflict with
- * "host/path" (that is, only "./path" or "../path" are allowed);
- * 2. if neither scheme nor userinfo are present but port is, it must
- * be non-empty, to avoid conflict with "scheme:/...";
- * 3. if AllowRootless is not specified, rootless (or opaque) URIs are
- * not recognized;
- * 4. if AllowRootless is specified, disallow userinfo, preferring
- * "scheme:pa@th" over "user:pass@host", and even "host:port" when
- * host contains only scheme-legal characters.
- */
+ * 1. do not allow relative-path-only URIs when they can conflict with
+ * "host/path" (that is, only "./path" or "../path" are allowed);
+ * 2. if neither scheme nor userinfo are present but port is, it must
+ * be non-empty, to avoid conflict with "scheme:/...";
+ * 3. if AllowRootless is not specified, rootless (or opaque) URIs are
+ * not recognized;
+ * 4. if AllowRootless is specified, disallow userinfo, preferring
+ * "scheme:pa@th" over "user:pass@host", and even "host:port" when
+ * host contains only scheme-legal characters.
+ */
FEATURE_NAME(NoRelPath),
// standard prefers that all hex escapes were using uppercase A-F
FEATURE_NAME(UpperEncoded),
-
+
// internal usage: decode all encoded symbols
FEATURE_NAME(DecodeANY),
-
+
// add before this line
_FeatureMAX
};
-
+
protected:
enum EPrivate : ui32 {
FEATURE_FLAG(DecodeANY),
FEATURE_FLAG(DecodeFieldAllowed),
FEATURE_FLAG(DecodeStandardExtra),
};
-
+
public:
enum EPublic : ui32 {
FeatureMAX = _FeatureMAX,
@@ -297,27 +297,27 @@ namespace NUri {
FEATURE_FLAG_NAME(HierURI) = FEATURE_FLAG_NAME(NoRelPath),
FEATURE_FLAG(UpperEncoded),
};
-
-#undef FEATURE_NAME
-#undef FEATURE_FLAG
-
+
+#undef FEATURE_NAME
+#undef FEATURE_FLAG
+
public:
//==============================
enum ESets {
// these are guaranteed and will change buffer size
-
+
FeatureDecodeStandard = 0 | FeatureDecodeUnreserved | FeatureDecodeStandardExtra,
-
+
FeaturesDecodeExtended = 0 | FeatureDecodeExtendedASCII | FeatureDecodeExtendedDelim,
-
+
FeaturesDecode = 0 | FeatureDecodeUnreserved | FeatureDecodeStandard | FeaturesDecodeExtended,
-
+
FeaturesEncodeExtended = 0 | FeatureEncodeExtendedASCII | FeatureEncodeExtendedDelim,
-
+
FeaturesEncode = 0 | FeatureEncodeForSQL | FeatureEncodeSpace | FeatureEncodeCntrl | FeatureEncodePercent | FeaturesEncodeExtended,
// these are not guaranteed to apply to a given field
-
+
FeatureDecodeAllowed = 0 | FeatureDecodeUnreserved | FeatureDecodeFieldAllowed,
FeaturesMaybeDecode = 0 | FeaturesDecode | FeatureDecodeAllowed,
@@ -325,18 +325,18 @@ namespace NUri {
FeaturesMaybeEncode = 0 | FeaturesEncode,
FeaturesEncodeDecode = 0 | FeaturesMaybeEncode | FeaturesMaybeDecode,
-
+
FeaturesAllEncoder = 0 | FeaturesEncodeDecode | FeatureDecodeANY | FeatureToLower | FeatureUpperEncoded | FeatureEncodeSpaceAsPlus,
-
+
//==============================
FeaturesNormalizeSet = 0 | FeaturePathOperation | FeatureToLower | FeatureDecodeAllowed | FeatureEncodeSpaceAsPlus | FeatureEncodeForSQL | FeaturePathStripRootParent | FeatureTryToFix | FeatureUpperEncoded,
-
+
FeaturesDefault = 0 // it reproduces old parsedURL
| FeaturePathOperation | FeaturePathDenyRootParent | FeatureCheckHost,
// essentially allows all valid RFC urls and keeps them as-is
FeaturesBare = 0 | FeatureAuthSupported | FeatureSchemeFlexible | FeatureAllowEmptyPath,
-
+
FeaturesAll = 0 | FeatureAuthSupported | FeatureSchemeFlexible | FeatureCheckHost | FeaturesNormalizeSet,
// Deprecated, use FeaturesRecommended
@@ -347,14 +347,14 @@ namespace NUri {
| FeatureDecodeUnreserved // 6.2.2.2
| FeaturePathOperation // 6.2.2.3
| FeaturePathDenyRootParent | FeatureSchemeKnown | FeatureConvertHostIDN | FeatureRemoteOnly | FeatureHashBangToEscapedFragment | FeatureCheckHost,
-
+
// these are mutually exclusive
FeaturesPath = 0 | FeaturePathDenyRootParent | FeaturePathStripRootParent,
-
+
FeaturesEscapedFragment = 0 | FeatureEscapedToHashBangFragment | FeatureHashBangToEscapedFragment,
-
+
FeaturesCheckSpecialChar = 0 | FeatureEncodeSpace | FeatureEncodeCntrl | FeatureEncodePercent,
-
+
FeaturesEncodePChar = 0 | FeatureUpperEncoded | FeaturesEncodeDecode | FeaturesCheckSpecialChar,
// http://wiki.yandex-team.ru/robot/newDesign/dups/normolization
@@ -362,8 +362,8 @@ namespace NUri {
FeaturesRobot = FeaturesRecommended
};
- };
-
+ };
+
static inline int strnicmp(const char* lt, const char* rt, size_t len) {
return lt == rt ? 0 : ::strnicmp(lt, rt, len);
}
@@ -371,16 +371,16 @@ namespace NUri {
static inline int CompareNoCasePrefix(const TStringBuf& lt, const TStringBuf& rt) {
return strnicmp(lt.data(), rt.data(), rt.length());
}
-
+
static inline bool EqualNoCase(const TStringBuf& lt, const TStringBuf& rt) {
return lt.length() == rt.length() && 0 == CompareNoCasePrefix(lt, rt);
- }
-
+ }
+
static inline int CompareNoCase(const TStringBuf& lt, const TStringBuf& rt) {
if (lt.length() == rt.length())
return CompareNoCasePrefix(lt, rt);
return lt.length() < rt.length() ? -1 : 1;
- }
+ }
class TSchemeInfo {
public:
@@ -398,7 +398,7 @@ namespace NUri {
bool Matches(const TStringBuf& scheme) const {
return EqualNoCase(scheme, Str);
}
-
+
public:
static const TSchemeInfo& Get(const TStringBuf& scheme);
static const TSchemeInfo& Get(TScheme::EKind scheme) {
@@ -488,24 +488,24 @@ namespace NUri {
const char* ParsedStateToString(const TState::EParsed& t);
const char* SchemeKindToString(const TScheme::EKind& t);
-}
-
+}
+
Y_DECLARE_OUT_SPEC(inline, NUri::TField::EField, out, t) {
- out << NUri::FieldToString(t);
+ out << NUri::FieldToString(t);
}
Y_DECLARE_OUT_SPEC(inline, NUri::TScheme::EKind, out, t) {
- out << NUri::SchemeKindToString(t);
+ out << NUri::SchemeKindToString(t);
}
Y_DECLARE_OUT_SPEC(inline, NUri::TState::EParsed, out, t) {
- out << NUri::ParsedStateToString(t);
+ out << NUri::ParsedStateToString(t);
}
static inline ui16 DefaultPort(NUri::TScheme::EKind scheme) {
- return NUri::TSchemeInfo::GetDefaultPort(scheme);
+ return NUri::TSchemeInfo::GetDefaultPort(scheme);
}
static inline NUri::TScheme::EKind SchemeKind(const TStringBuf& scheme) {
- return NUri::TSchemeInfo::GetKind(scheme);
+ return NUri::TSchemeInfo::GetKind(scheme);
}
diff --git a/library/cpp/uri/encode.cpp b/library/cpp/uri/encode.cpp
index 2f63d8140a..584fb1bac9 100644
--- a/library/cpp/uri/encode.cpp
+++ b/library/cpp/uri/encode.cpp
@@ -1,33 +1,33 @@
-#include "encode.h"
+#include "encode.h"
#include <util/generic/singleton.h>
-namespace NUri {
+namespace NUri {
namespace NEncode {
-// http://tools.ietf.org/html/rfc3986#section-2.2
-#define GENDELIMS0 ":/?#[]@"
-#define SUBDELIMS0 "!$&'()*+,;="
-// http://tools.ietf.org/html/rfc3986#section-2.3
-#define UNRESERVED "-._~"
-
-// now find subsets which can sometimes be decoded
-
-// remove '#' which can't ever be decoded
-// don't mark anything allowed for pass (pass is completely encoded)
-// safe in path, qry, frag
-#define GENDELIMS1 ":@"
-// allowed in qry, frag
-#define GENDELIMS2 "/?"
-
-// qry-unsafe chars
-#define SUBDELIMS1 "&+=;"
-// rest allowed in qry, frag
-#define SUBDELIMS2 "!$'()*,"
-
+// http://tools.ietf.org/html/rfc3986#section-2.2
+#define GENDELIMS0 ":/?#[]@"
+#define SUBDELIMS0 "!$&'()*+,;="
+// http://tools.ietf.org/html/rfc3986#section-2.3
+#define UNRESERVED "-._~"
+
+// now find subsets which can sometimes be decoded
+
+// remove '#' which can't ever be decoded
+// don't mark anything allowed for pass (pass is completely encoded)
+// safe in path, qry, frag
+#define GENDELIMS1 ":@"
+// allowed in qry, frag
+#define GENDELIMS2 "/?"
+
+// qry-unsafe chars
+#define SUBDELIMS1 "&+=;"
+// rest allowed in qry, frag
+#define SUBDELIMS2 "!$'()*,"
+
const TEncoder::TGrammar& TEncoder::Grammar() {
return *Singleton<TEncoder::TGrammar>();
}
-
+
// initialize the grammar map
TEncoder::TGrammar::TGrammar() {
// first set up unreserved characters safe in any field
@@ -36,37 +36,37 @@ namespace NUri {
AddRng('A', 'Z', ECFUpper, featUnres | TFeature::FeatureToLower);
AddRng('a', 'z', ECFLower, featUnres);
Add(UNRESERVED, ECFUnres, featUnres);
-
+
// XXX: standard "safe" set used previously "-_.!~*();/:@$,", with comment:
// alnum + reserved + mark + ( '[', ']') - ('=' '+' '&' '\'' '"' '\\' '?')
Add("!*();/:@$,", ECFStdrd, TFeature::FeatureDecodeStandardExtra);
-
+
// now field-specific subsets of reserved characters (gen-delims + sub-delims)
const ui64 featSafe = TFeature::FeatureDecodeFieldAllowed;
-
+
Add(GENDELIMS1, 0, featSafe, TField::FlagPath | TField::FlagQuery | TField::FlagFrag);
Add(GENDELIMS2, 0, featSafe, TField::FlagQuery | TField::FlagFrag);
-
+
Add(SUBDELIMS1, 0, featSafe, TField::FlagUser);
Add(SUBDELIMS2, 0, featSafe, TField::FlagUser | TField::FlagQuery | TField::FlagFrag);
-
+
// control chars
AddRng(0x00, 0x20, TFeature::FeatureEncodeCntrl);
Add(0x7f, TFeature::FeatureEncodeCntrl);
-
+
// '%' starts a percent-encoded sequence
Add('%', TFeature::FeatureDecodeANY | TFeature::FeatureEncodePercent);
-
+
// extended ASCII
AddRng(128, 255, TFeature::FeatureEncodeExtendedASCII | TFeature::FeatureDecodeExtendedASCII);
-
+
// extended delims
Add("\"<>[\\]^`{|}", TFeature::FeatureEncodeExtendedDelim | TFeature::FeatureDecodeExtendedDelim);
-
+
// add characters with other features
Add(' ', TFeature::FeatureEncodeSpace | TFeature::FeatureEncodeSpaceAsPlus);
Add("'\"\\", TFeature::FeatureEncodeForSQL);
-
+
GetMutable(':').EncodeFld |= TField::FlagUser;
GetMutable('?').EncodeFld |= TField::FlagPath;
GetMutable('#').EncodeFld |= TField::FlagPath | TField::FlagQuery;
@@ -83,44 +83,44 @@ namespace NUri {
return true;
return (fldmask & DecodeFld) && (flags & TFeature::FeatureDecodeFieldAllowed);
}
-
+
const int dD = 'a' - 'A';
-
+
int TEncodeMapper::EncodeSym(unsigned char& ch) const {
const TCharFlags& chflags = TEncoder::GetFlags(ch);
const ui64 flags = Flags & chflags.FeatFlags;
-
+
if (flags & TFeature::FeatureToLower)
ch += dD;
-
+
if (Q_DecodeAny)
return -1;
-
+
if (flags & TFeature::FeaturesEncode)
return 1;
-
+
if (' ' == ch) {
if (Q_EncodeSpcAsPlus)
ch = '+';
return 0;
}
-
+
return 0;
}
-
+
int TEncodeMapper::EncodeHex(unsigned char& ch) const {
const TCharFlags& chflags = TEncoder::GetFlags(ch);
const ui64 flags = Flags & chflags.FeatFlags;
-
+
if (flags & TFeature::FeatureToLower)
ch += dD;
-
+
if (Q_DecodeAny)
return -1;
-
+
if (chflags.IsDecode(FldMask, Flags))
return 0;
-
+
if (' ' == ch) {
if (!Q_EncodeSpcAsPlus)
return 1;
@@ -128,21 +128,21 @@ namespace NUri {
return 0;
}
- return 1;
+ return 1;
}
-
+
bool TEncodeToMapper::Encode(unsigned char ch) const {
if (Q_DecodeAny)
return false;
-
+
const TCharFlags& chflags = TEncoder::GetFlags(ch);
if (FldMask & chflags.EncodeFld)
return true;
-
+
const ui64 flags = Flags & chflags.FeatFlags;
return (flags & TFeature::FeaturesEncode);
}
-
+
TEncoder::TEncoder(IOutputStream& out, const TEncodeMapper& fldsrc, const TEncodeToMapper& flddst)
: Out(out)
, FldSrc(fldsrc)
@@ -151,12 +151,12 @@ namespace NUri {
, HexValue(0)
{
}
-
+
IOutputStream& TEncoder::Hex(IOutputStream& out, unsigned char val) {
static const char sHexCodes[] = "0123456789ABCDEF";
return out << sHexCodes[(val >> 4) & 0xF] << sHexCodes[val & 0xF];
}
-
+
IOutputStream& TEncoder::EncodeAll(IOutputStream& out, const TStringBuf& val) {
for (size_t i = 0; i != val.length(); ++i)
Encode(out, val[i]);
@@ -173,7 +173,7 @@ namespace NUri {
}
return out;
}
-
+
IOutputStream& TEncoder::EncodeField(
IOutputStream& out, const TStringBuf& val, TField::EField fld) {
const ui32 fldmask = ui32(1) << fld;
@@ -210,11 +210,11 @@ namespace NUri {
Out << ch;
return;
}
-
+
Out << '%';
if (escapepct)
Out.Write("25", 2); // '%'
Hex(Out, ch);
}
- }
+ }
}
diff --git a/library/cpp/uri/encode.h b/library/cpp/uri/encode.h
index 6a817bf6fd..a9ece15427 100644
--- a/library/cpp/uri/encode.h
+++ b/library/cpp/uri/encode.h
@@ -1,10 +1,10 @@
-#pragma once
-
-#include "common.h"
-
-#include <util/stream/output.h>
+#pragma once
-namespace NUri {
+#include "common.h"
+
+#include <util/stream/output.h>
+
+namespace NUri {
namespace NEncode {
#define CHAR_TYPE_NAME(f) _ECT##f
#define CHAR_TYPE_FLAG(f) ECF##f = 1u << CHAR_TYPE_NAME(f)
@@ -16,7 +16,7 @@ namespace NUri {
CHAR_TYPE_NAME(Unres),
CHAR_TYPE_NAME(Stdrd),
};
-
+
enum ECharFlag {
CHAR_TYPE_FLAG(Digit),
CHAR_TYPE_FLAG(Lower),
@@ -30,8 +30,8 @@ namespace NUri {
ECGStdrd = ECGUnres | ECFStdrd,
};
-#undef CHAR_TYPE_NAME
-#undef CHAR_TYPE_FLAG
+#undef CHAR_TYPE_NAME
+#undef CHAR_TYPE_FLAG
struct TCharFlags {
ui32 TypeFlags;
@@ -65,7 +65,7 @@ namespace NUri {
// should we decode an encoded character
bool IsDecode(ui32 fldmask, ui64 flags) const;
};
-
+
class TEncodeMapperBase {
protected:
TEncodeMapperBase()
@@ -80,13 +80,13 @@ namespace NUri {
, Q_DecodeAny(flags & TFeature::FeatureDecodeANY)
{
}
-
+
protected:
const ui64 Flags;
const ui32 FldMask;
const bool Q_DecodeAny; // this is a special option for username/password
};
-
+
// maps a sym or hex character and indicates whether it has to be encoded
class TEncodeMapper
: public TEncodeMapperBase {
@@ -99,11 +99,11 @@ namespace NUri {
// negative=sym, positive=hex, zero=maybesym
int EncodeSym(unsigned char&) const;
int EncodeHex(unsigned char&) const;
-
+
protected:
const bool Q_EncodeSpcAsPlus;
};
-
+
// indicates whether a character has to be encoded when copying to a field
class TEncodeToMapper
: public TEncodeMapperBase {
@@ -121,16 +121,16 @@ namespace NUri {
}
bool Encode(unsigned char) const;
};
-
+
class TEncoder {
public:
TEncoder(IOutputStream& out, const TEncodeMapper& fldsrc, const TEncodeToMapper& flddst = TEncodeToMapper());
-
+
ui64 ReEncode(const TStringBuf& url);
ui64 ReEncode(const char* str, size_t len) {
return ReEncode(TStringBuf(str, len));
}
-
+
protected:
static bool IsType(unsigned char c, ui64 flags) {
return GetFlags(c).TypeFlags & flags;
@@ -188,7 +188,7 @@ namespace NUri {
static IOutputStream& EncodeField(IOutputStream& out, const TStringBuf& val, TField::EField fld);
static IOutputStream& EncodeField(IOutputStream& out, const TStringBuf& val, TField::EField fld, ui64 flags);
-
+
static IOutputStream& Encode(IOutputStream& out, const TStringBuf& val) {
return EncodeField(out, val, TField::FieldAllMAX);
}
@@ -200,20 +200,20 @@ namespace NUri {
public:
class TGrammar {
TCharFlags Map_[256];
-
+
public:
TGrammar();
const TCharFlags& Get(unsigned char ch) const {
return Map_[ch];
}
-
+
TCharFlags& GetMutable(unsigned char ch) {
return Map_[ch];
}
TCharFlags& Add(unsigned char ch, const TCharFlags& val) {
return GetMutable(ch).Add(val);
}
-
+
void AddRng(unsigned char lo, unsigned char hi, const TCharFlags& val) {
for (unsigned i = lo; i <= hi; ++i)
Add(i, val);
@@ -221,7 +221,7 @@ namespace NUri {
void AddRng(unsigned char lo, unsigned char hi, ui32 type, ui64 feat, ui32 decmask = 0, ui32 encmask = 0) {
AddRng(lo, hi, TCharFlags(type, feat, decmask, encmask));
}
-
+
void Add(const TStringBuf& set, const TCharFlags& val) {
for (size_t i = 0; i != set.length(); ++i)
Add(set[i], val);
@@ -230,9 +230,9 @@ namespace NUri {
Add(set, TCharFlags(type, feat, decmask, encmask));
}
};
-
+
static const TGrammar& Grammar();
-
+
protected:
IOutputStream& Out;
const TEncodeMapper FldSrc;
@@ -276,7 +276,7 @@ namespace NUri {
void Do(unsigned char, int);
};
}
-
+
using TEncoder = NEncode::TEncoder;
}
diff --git a/library/cpp/uri/encodefsm.rl6 b/library/cpp/uri/encodefsm.rl6
index 396fd40b36..6a323aa85a 100644
--- a/library/cpp/uri/encodefsm.rl6
+++ b/library/cpp/uri/encodefsm.rl6
@@ -4,21 +4,21 @@
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
-namespace NUri {
-namespace NEncode {
-
+namespace NUri {
+namespace NEncode {
+
%%{
- machine TEncoder;
+ machine TEncoder;
- hex = (
- digit >{ HexDigit(fc); } |
- [A-F] >{ HexUpper(fc); } |
- [a-f] >{ HexLower(fc); }
- );
+ hex = (
+ digit >{ HexDigit(fc); } |
+ [A-F] >{ HexUpper(fc); } |
+ [a-f] >{ HexLower(fc); }
+ );
- escaped = ( "%" hex hex )
- > { HexReset(); }
- % { DoHex(); };
+ escaped = ( "%" hex hex )
+ > { HexReset(); }
+ % { DoHex(); };
bad_escaped = ( "%" hex )
% {
@@ -30,22 +30,22 @@ namespace NEncode {
main := ( escaped | bad_escaped | sym )**;
- write data;
+ write data;
}%%
-ui64 TEncoder::ReEncode(const TStringBuf &url)
+ui64 TEncoder::ReEncode(const TStringBuf &url)
{
- const char *p = url.data();
- const char *pe = p + url.length();
- const char *eof = pe;
+ const char *p = url.data();
+ const char *pe = p + url.length();
+ const char *eof = pe;
int cs;
- OutFlags = 0;
+ OutFlags = 0;
%% write init;
%% write exec;
-
- return OutFlags;
+
+ return OutFlags;
+}
+
+}
}
-
-}
-}
diff --git a/library/cpp/uri/http_url.h b/library/cpp/uri/http_url.h
index 70d53c7791..7c8e8d844d 100644
--- a/library/cpp/uri/http_url.h
+++ b/library/cpp/uri/http_url.h
@@ -1,77 +1,77 @@
#pragma once
-#include "uri.h"
-#include "other.h"
+#include "uri.h"
+#include "other.h"
+
+// XXX: use NUri::TUri directly; this whole file is for backwards compatibility
-// XXX: use NUri::TUri directly; this whole file is for backwards compatibility
-
class THttpURL
: public NUri::TUri {
-public:
- typedef TField::EFlags TFlags;
- typedef TField::EField TField;
- typedef TScheme::EKind TSchemeKind;
- typedef TState::EParsed TParsedState;
+public:
+ typedef TField::EFlags TFlags;
+ typedef TField::EField TField;
+ typedef TScheme::EKind TSchemeKind;
+ typedef TState::EParsed TParsedState;
-public:
- enum {
- FeatureUnescapeStandard = TFeature::FeatureDecodeStandard,
+public:
+ enum {
+ FeatureUnescapeStandard = TFeature::FeatureDecodeStandard,
FeatureEscSpace = TFeature::FeatureEncodeSpaceAsPlus,
FeatureEscapeUnescaped = TFeature::FeatureEncodeExtendedASCII,
FeatureNormalPath = TFeature::FeaturePathStripRootParent,
};
-public:
- THttpURL(unsigned defaultPort = 80)
- : TUri(defaultPort)
+public:
+ THttpURL(unsigned defaultPort = 80)
+ : TUri(defaultPort)
{
}
-
+
THttpURL(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0)
- : TUri(host, port, path, query, scheme, defaultPort)
+ : TUri(host, port, path, query, scheme, defaultPort)
{
}
- THttpURL(const TUri& url)
- : TUri(url)
+ THttpURL(const TUri& url)
+ : TUri(url)
{
}
-
-public: // XXX: don't use any of these legacy methods below
-public: // use TUri::GetField() instead
- /// will return null-terminated if fld is not dirty
+
+public: // XXX: don't use any of these legacy methods below
+public: // use TUri::GetField() instead
+ /// will return null-terminated if fld is not dirty
const char* Get(EField fld) const {
- return GetField(fld).data();
- }
-
-public: // use TUriUpdate class so that Rewrite() is only called once
+ return GetField(fld).data();
+ }
+
+public: // use TUriUpdate class so that Rewrite() is only called once
void Set(EField field, const TStringBuf& value) {
- if (SetInMemory(field, value))
- Rewrite();
- }
-
- template <size_t size>
+ if (SetInMemory(field, value))
+ Rewrite();
+ }
+
+ template <size_t size>
void Set(EField field, const char (&value)[size]) {
- if (SetInMemory(field, value))
- Rewrite();
- }
-
-public: // use TUri::FldXXX methods for better control
- // Partial quick set of the field, can be called for
- // multiple fields
+ if (SetInMemory(field, value))
+ Rewrite();
+ }
+
+public: // use TUri::FldXXX methods for better control
+ // Partial quick set of the field, can be called for
+ // multiple fields
bool SetInMemory(EField field, const TStringBuf& value) {
- return FldMemSet(field, value);
- }
-
- // clears a field
+ return FldMemSet(field, value);
+ }
+
+ // clears a field
void Reset(EField field) {
- FldClr(field);
- }
+ FldClr(field);
+ }
};
-
+
static inline const char* HttpURLParsedStateToString(const NUri::TState::EParsed& t) {
- return NUri::ParsedStateToString(t);
-}
+ return NUri::ParsedStateToString(t);
+}
static inline const char* HttpUrlSchemeKindToString(const NUri::TScheme::EKind& t) {
- return NUri::SchemeKindToString(t);
-}
+ return NUri::SchemeKindToString(t);
+}
diff --git a/library/cpp/uri/other.cpp b/library/cpp/uri/other.cpp
index 5ece2e6020..b23a5b68a9 100644
--- a/library/cpp/uri/other.cpp
+++ b/library/cpp/uri/other.cpp
@@ -1,11 +1,11 @@
-#include "other.h"
+#include "other.h"
-#include <util/string/util.h>
+#include <util/string/util.h>
#include <util/system/yassert.h>
/********************************************************/
/********************************************************/
-
+
static const Tr InvertTr(".:/?#", "\005\004\003\002\001");
static const Tr RevertTr("\005\004\003\002\001", ".:/?#");
diff --git a/library/cpp/uri/parse.cpp b/library/cpp/uri/parse.cpp
index 49e087cc30..1db4e008c4 100644
--- a/library/cpp/uri/parse.cpp
+++ b/library/cpp/uri/parse.cpp
@@ -1,8 +1,8 @@
#include "parse.h"
-#include "common.h"
-#include "encode.h"
+#include "common.h"
+#include "encode.h"
-namespace NUri {
+namespace NUri {
const TParseFlags TParser::FieldFlags[] =
{
TParseFlags(0 // FieldScheme
@@ -23,27 +23,27 @@ namespace NUri {
TParseFlags(0 // FieldHost
| TFeature::FeatureToLower | TFeature::FeatureUpperEncoded | (TFeature::FeaturesMaybeEncode & ~TFeature::FeatureEncodeExtendedDelim),
0 | TFeature::FeaturesMaybeDecode)
-
+
,
TParseFlags(0 // FieldPort
,
0)
-
+
,
TParseFlags(0 // FieldPath
| TFeature::FeaturesEncodePChar | TFeature::FeaturePathOperation,
0 | TFeature::FeatureToLower | TFeature::FeatureEncodeSpaceAsPlus)
-
+
,
TParseFlags(0 // FieldQuery
| TFeature::FeaturesEncodePChar | TFeature::FeatureEncodeSpaceAsPlus,
0 | TFeature::FeatureToLower)
-
+
,
TParseFlags(0 // FieldFragment
| TFeature::FeaturesEncodePChar,
0 | TFeature::FeatureToLower | TFeature::FeatureEncodeSpaceAsPlus)};
-
+
namespace NParse {
void TRange::AddRange(const TRange& range, ui64 mask) {
FlagsAllPlaintext |= range.FlagsAllPlaintext;
@@ -59,17 +59,17 @@ namespace NUri {
}
}
-
+
void TParser::copyRequirementsImpl(const char* ptr) {
Y_ASSERT(0 != CurRange.FlagsAllPlaintext);
Y_UNUSED(ptr);
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(ptr, __FUNCTION__)
- << " all=[" << IntToString<16>(CurRange.FlagsAllPlaintext)
- << "] enc=[" << IntToString<16>(CurRange.FlagsEncodeMasked)
+ << " all=[" << IntToString<16>(CurRange.FlagsAllPlaintext)
+ << "] enc=[" << IntToString<16>(CurRange.FlagsEncodeMasked)
<< " & " << IntToString<16>(Flags.Allow | Flags.Extra) << "]";
PrintTail(CurRange.Beg, ptr);
-#endif
+#endif
for (int i = 0; i < TField::FieldUrlMAX; ++i) {
const TField::EField fld = TField::EField(i);
TSection& section = Sections[fld];
@@ -92,22 +92,22 @@ namespace NUri {
}
void TParser::PctEndImpl(const char* ptr) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(PctBegin, __FUNCTION__);
PrintTail(PctBegin, ptr);
-#else
+#else
Y_UNUSED(ptr);
-#endif
+#endif
setRequirement(PctBegin, TEncoder::GetFlags('%').FeatFlags);
PctBegin = nullptr;
}
-
+
void TParser::HexSet(const char* ptr) {
Y_ASSERT(nullptr != PctBegin);
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(ptr, __FUNCTION__);
PrintTail(PctBegin, ptr + 1);
-#endif
+#endif
PctBegin = nullptr;
const unsigned char ch = HexValue;
ui64 flags = TEncoder::GetFlags('%').FeatFlags | TEncoder::GetFlags(ch).FeatFlags;
@@ -116,14 +116,14 @@ namespace NUri {
}
TState::EParsed TParser::ParseImpl() {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(UriStr.data(), "[Parsing]") << "URL";
PrintTail(UriStr);
-#endif
-
+#endif
+
const bool ok = doParse(UriStr.data(), UriStr.length());
-
-#ifdef DO_PRN
+
+#ifdef DO_PRN
Cdbg << (ok ? "[Parsed]" : "[Failed]");
for (int idx = 0; idx < TField::FieldUrlMAX; ++idx) {
const TSection& section = Sections[idx];
@@ -131,8 +131,8 @@ namespace NUri {
Cdbg << ' ' << TField::EField(idx) << "=[" << section.Get() << ']';
}
Cdbg << Endl;
-#endif
-
+#endif
+
if (!ok) {
if (!(Flags & TFeature::FeatureTryToFix) || !Sections[TField::FieldFrag].Beg)
return TState::ParsedBadFormat;
@@ -141,7 +141,7 @@ namespace NUri {
}
if ((Flags & TFeature::FeatureDenyNetworkPath) && IsNetPath())
- return TState::ParsedBadFormat;
+ return TState::ParsedBadFormat;
const TSection& scheme = Sections[TField::FieldScheme];
Scheme = scheme.IsSet() ? TSchemeInfo::GetKind(scheme.Get()) : TScheme::SchemeEmpty;
@@ -151,19 +151,19 @@ namespace NUri {
// opaque case happens
if (schemeInfo.FldReq & TField::FlagHost)
return TState::ParsedBadFormat;
-
+
if (TScheme::SchemeEmpty == Scheme)
return TState::ParsedBadScheme;
-
+
if (Flags & TFeature::FeatureAllowRootless)
return TState::ParsedOK;
if (!(Flags & TFeature::FeatureSchemeFlexible))
return TState::ParsedBadScheme;
-
+
return TState::ParsedRootless;
}
-
+
checkSectionCollision(TField::FieldUser, TField::FieldHost);
checkSectionCollision(TField::FieldPass, TField::FieldPort);
@@ -199,9 +199,9 @@ namespace NUri {
if ((schemeInfo.FldReq & TField::FlagHost) || (Flags & TFeature::FeatureRemoteOnly))
if (!host.IsSet() || 0 == host.Len())
return TState::ParsedBadFormat;
- }
-
+ }
+
return TState::ParsedOK;
- }
-
+ }
+
}
diff --git a/library/cpp/uri/parse.h b/library/cpp/uri/parse.h
index 0d2ce86ddf..ca2358e572 100644
--- a/library/cpp/uri/parse.h
+++ b/library/cpp/uri/parse.h
@@ -1,20 +1,20 @@
-#pragma once
+#pragma once
-// #define DO_PRN
+// #define DO_PRN
-#include <cstddef>
+#include <cstddef>
-#include "common.h"
+#include "common.h"
#include <library/cpp/charset/doccodes.h>
-#include <util/generic/strbuf.h>
-#include <util/stream/output.h>
-#include <util/string/cast.h>
-#include <util/system/yassert.h>
+#include <util/generic/strbuf.h>
+#include <util/stream/output.h>
+#include <util/string/cast.h>
+#include <util/system/yassert.h>
-namespace NUri {
+namespace NUri {
class TParser;
-
+
namespace NParse {
class TRange {
public:
@@ -23,7 +23,7 @@ namespace NUri {
ui64 FlagsAllPlaintext;
ui32 Encode;
ui32 Decode;
-
+
public:
TRange(const char* beg = nullptr)
: Beg(beg)
@@ -33,51 +33,51 @@ namespace NUri {
, Decode(0)
{
}
-
+
void Reset(const char* beg = nullptr) {
*this = TRange(beg);
}
-
+
void AddRange(const TRange& range, ui64 mask);
-
+
void AddFlag(const char* ptr, ui64 mask, ui64 flag) {
if (0 != flag)
AddFlagImpl(ptr, mask, flag, flag);
}
-
+
void AddFlagExcept(const char* ptr, ui64 mask, ui64 flag, ui64 exclflag) {
if (0 != flag)
AddFlagImpl(ptr, mask, flag & ~exclflag, flag);
}
-
+
void AddFlagUnless(const char* ptr, ui64 mask, ui64 flag, ui64 exclmask) {
if (0 != flag)
AddFlagImpl(ptr, mask, flag, flag, exclmask);
}
-
+
void AddFlag(const char* ptr, ui64 mask, ui64 flag, ui64 exclflag, ui64 exclmask) {
if (0 != flag)
AddFlagImpl(ptr, mask, flag & ~exclflag, flag, exclmask);
}
-
+
private:
void AddFlagImpl(const char* ptr, ui64 mask, ui64 plainflag, ui64 encflag) {
AddFlagAllPlaintextImpl(ptr, plainflag);
AddFlagEncodeMaskedImpl(encflag & mask);
}
-
+
void AddFlagImpl(const char* ptr, ui64 mask, ui64 plainflag, ui64 encflag, ui64 exclmask) {
AddFlagAllPlaintextImpl(ptr, plainflag);
if (0 == (mask & exclmask))
AddFlagEncodeMaskedImpl(encflag & mask);
}
-
+
void AddFlagAllPlaintextImpl(const char* ptr, ui64 flag) {
if (nullptr == Beg)
Beg = ptr;
FlagsAllPlaintext |= flag;
}
-
+
void AddFlagEncodeMaskedImpl(ui64 flag) {
if (0 == flag)
return;
@@ -88,36 +88,36 @@ namespace NUri {
++Decode;
}
};
-
- }
-
+
+ }
+
class TSection
: protected NParse::TRange {
private:
friend class TParser;
-
+
private:
const char* End;
-
+
TSection(const char* beg = nullptr)
: NParse::TRange(beg)
, End(nullptr)
{
}
-
+
void Reset() {
Enter(nullptr);
}
-
+
void Reset(const char* pc) {
Y_ASSERT(!Beg || !pc || Beg < pc);
Reset();
}
-
+
void Enter(const char* pc) {
*this = TSection(pc);
}
-
+
bool Leave(const char* pc) {
Y_ASSERT(Beg);
End = pc;
@@ -133,40 +133,40 @@ namespace NUri {
bool IsSet() const {
return End;
}
-
+
TStringBuf Get() const {
return TStringBuf(Beg, End);
}
-
+
size_t Len() const {
return End - Beg;
}
-
+
size_t DecodedLen() const {
return Len() - 2 * Decode;
}
-
+
size_t EncodedLen() const {
return 2 * Encode + DecodedLen();
}
-
+
ui32 GetEncode() const {
return Encode;
}
-
+
ui32 GetDecode() const {
return Decode;
}
-
+
ui64 GetFlagsEncode() const {
return FlagsEncodeMasked;
}
-
+
ui64 GetFlagsAllPlaintext() const {
return FlagsAllPlaintext;
}
};
-
+
class TParser {
public:
TSection Sections[TField::FieldUrlMAX];
@@ -175,7 +175,7 @@ namespace NUri {
const TStringBuf UriStr;
TState::EParsed State;
ECharset Enc;
-
+
public:
TParser(const TParseFlags& flags, const TStringBuf& uri, ECharset enc = CODES_UTF8)
: Scheme(TScheme::SchemeEmpty)
@@ -218,97 +218,97 @@ namespace NUri {
ui64 GetFieldFlags(TField::EField fld) const {
return GetFieldFlags(fld, Flags);
}
-
+
protected:
static const TParseFlags FieldFlags[TField::FieldUrlMAX];
TSection::TRange CurRange;
unsigned HexValue;
const char* PctBegin;
-
-#ifdef DO_PRN
+
+#ifdef DO_PRN
IOutputStream& PrintAddr(const char* ptr) const {
return Cdbg << "[" << IntToString<16>(ui64(ptr)) << "] ";
}
-
+
IOutputStream& PrintHead(const char* ptr, const char* func) const {
return PrintAddr(ptr) << func << " ";
}
-
+
IOutputStream& PrintHead(const char* ptr, const char* func, const TField::EField& fld) const {
return PrintHead(ptr, func) << fld;
}
-
+
IOutputStream& PrintTail(const TStringBuf& val) const {
return Cdbg << " [" << val << "]" << Endl;
}
IOutputStream& PrintTail(const char* beg, const char* end) const {
return PrintTail(TStringBuf(beg, end));
}
-#endif
-
+#endif
+
void ResetSection(TField::EField fld, const char* pc = nullptr) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(pc, __FUNCTION__, fld);
PrintTail(pc);
-#endif
+#endif
Sections[fld].Reset(pc);
}
void storeSection(const TStringBuf& val, TField::EField fld) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(val.data(), __FUNCTION__, fld);
PrintTail(val);
-#endif
+#endif
Sections[fld].Set(val);
}
-
+
void startSection(const char* pc, TField::EField fld) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(pc, __FUNCTION__, fld);
PrintTail(pc);
-#endif
+#endif
copyRequirements(pc);
Sections[fld].Enter(pc);
}
void finishSection(const char* pc, TField::EField fld) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(pc, __FUNCTION__, fld);
PrintTail(pc);
-#endif
+#endif
if (Sections[fld].Leave(pc))
copyRequirements(pc);
}
void setRequirement(const char* ptr, ui64 flags) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(ptr, __FUNCTION__) << IntToString<16>(flags)
<< " & mask=" << IntToString<16>(Flags.Allow | Flags.Extra);
PrintTail(ptr);
-#endif
+#endif
CurRange.AddFlag(ptr, Flags.Allow | Flags.Extra, flags);
}
-
+
void setRequirementExcept(const char* ptr, ui64 flags, ui64 exclflag) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(ptr, __FUNCTION__) << IntToString<16>(flags)
<< " & exclflag=" << IntToString<16>(exclflag)
<< " & mask=" << IntToString<16>(Flags.Allow | Flags.Extra);
PrintTail(ptr);
-#endif
+#endif
CurRange.AddFlagExcept(ptr, Flags.Allow | Flags.Extra, flags, exclflag);
}
-
+
void setRequirementUnless(const char* ptr, ui64 flags, ui64 exclmask) {
-#ifdef DO_PRN
+#ifdef DO_PRN
PrintHead(ptr, __FUNCTION__) << IntToString<16>(flags)
<< " & exclmask=" << IntToString<16>(exclmask)
<< " & mask=" << IntToString<16>(Flags.Allow | Flags.Extra);
PrintTail(ptr);
-#endif
+#endif
CurRange.AddFlagUnless(ptr, Flags.Allow | Flags.Extra, flags, exclmask);
}
-
+
void copyRequirementsImpl(const char* ptr);
void copyRequirements(const char* ptr) {
PctEnd(ptr);
@@ -347,7 +347,7 @@ namespace NUri {
HexReset();
PctBegin = ptr;
}
-
+
void checkSectionCollision(TField::EField fld1, TField::EField fld2) {
if (Sections[fld1].IsSet() && Sections[fld2].IsSet() && Sections[fld1].Beg == Sections[fld2].Beg) {
Sections[fld1].Reset();
@@ -357,5 +357,5 @@ namespace NUri {
bool doParse(const char* str_beg, size_t length);
TState::EParsed ParseImpl();
};
-
+
}
diff --git a/library/cpp/uri/parsefsm.rl6 b/library/cpp/uri/parsefsm.rl6
index 62c05c51d0..7097723650 100644
--- a/library/cpp/uri/parsefsm.rl6
+++ b/library/cpp/uri/parsefsm.rl6
@@ -5,10 +5,10 @@
#endif
%%{
- machine TParser;
+ machine TParser;
- #================================================
- # RFC 3986 http://tools.ietf.org/html/rfc3986
+ #================================================
+ # RFC 3986 http://tools.ietf.org/html/rfc3986
# with some modifications
#================================================
# The RegEx
@@ -27,475 +27,475 @@
# $8 = #Related
# $9 = Related
#
- # So $2:scheme $4:authority $5:path $7:query $9:fragment
+ # So $2:scheme $4:authority $5:path $7:query $9:fragment
+ #================================================
+
+
#================================================
+ # List of all ASCII characters and where they can be used
+ #================================================
+
+ # 0-31 x00-1F cntrl ext_cntrl
+ # 32 x20 space ext_space
+ # 33 x21 ! sub_delims
+ # 34 x22 " ext_delims
+ # 35 x23 # gen_delims / f=frag
+ # 36 x24 $ sub_delims
+ # 37 x25 % PCT
+ # 38 x26 & sub_delims
+ # 39 x27 ' sub_delims
+ # 40 x28 ( sub_delims
+ # 41 x29 ) sub_delims
+ # 42 x2A * sub_delims
+ # 43 x2B + sub_delims
+ # 44 x2C , sub_delims
+ # 45 x2D - unreserved
+ # 46 x2E . unreserved
+ # 47 x2F / gen_delims / f=path,qry,frag
+ # 48-57 x30-39 0-9 unreserved
+ # 58 x3A : gen_delims / f=pass,path,qry,frag
+ # 59 x3B ; sub_delims
+ # 60 x3C < ext_delims
+ # 61 x3D = sub_delims
+ # 62 x3E > ext_delims
+ # 63 x3F ? gen_delims / f=qry,frag
+ # 64 x40 @ gen_delims / f=path,qry,frag
+ # 65-90 x41-5A A-Z unreserved
+ # 91 x5B [ gen_delims / ext_delims
+ # 92 x5C \ ext_delims
+ # 93 x5D ] gen_delims / ext_delims
+ # 94 x5E ^ ext_delims
+ # 95 x5F _ unreserved
+ # 96 x60 ` ext_delims
+ # 97-122 x61-7A a-z unreserved
+ # 123 x7B { ext_delims
+ # 124 x7C | ext_delims
+ # 125 x7D } ext_delims
+ # 126 x7E ~ unreserved
+ # 127 x7F DEL ext_cntrl
+ # 128-255 x80-FF ext_ascii
+
+
+ #================================================
+ # Actions used in multiple definitions
+ #================================================
+
+ action act_req_enc_sql { REQ(fpc, FeatureEncodeForSQL) }
+
+ # REQ must apply to a char in range but not after the range has been reset
+ action act_req_pathop { REQ(fpc - 1, FeaturePathOperation) }
+
+ action act_clr_scheme { CLR(fpc, Scheme) }
+ action act_clr_user { CLR(fpc, User) }
+ action act_clr_host { CLR(fpc, Host) }
+ action act_beg_host { BEG(fpc, Host) }
+ action act_end_host { END(fpc, Host) }
+ action act_beg_path { BEG(fpc, Path) }
+ action act_end_path { END(fpc, Path) }
- #================================================
- # List of all ASCII characters and where they can be used
- #================================================
-
- # 0-31 x00-1F cntrl ext_cntrl
- # 32 x20 space ext_space
- # 33 x21 ! sub_delims
- # 34 x22 " ext_delims
- # 35 x23 # gen_delims / f=frag
- # 36 x24 $ sub_delims
- # 37 x25 % PCT
- # 38 x26 & sub_delims
- # 39 x27 ' sub_delims
- # 40 x28 ( sub_delims
- # 41 x29 ) sub_delims
- # 42 x2A * sub_delims
- # 43 x2B + sub_delims
- # 44 x2C , sub_delims
- # 45 x2D - unreserved
- # 46 x2E . unreserved
- # 47 x2F / gen_delims / f=path,qry,frag
- # 48-57 x30-39 0-9 unreserved
- # 58 x3A : gen_delims / f=pass,path,qry,frag
- # 59 x3B ; sub_delims
- # 60 x3C < ext_delims
- # 61 x3D = sub_delims
- # 62 x3E > ext_delims
- # 63 x3F ? gen_delims / f=qry,frag
- # 64 x40 @ gen_delims / f=path,qry,frag
- # 65-90 x41-5A A-Z unreserved
- # 91 x5B [ gen_delims / ext_delims
- # 92 x5C \ ext_delims
- # 93 x5D ] gen_delims / ext_delims
- # 94 x5E ^ ext_delims
- # 95 x5F _ unreserved
- # 96 x60 ` ext_delims
- # 97-122 x61-7A a-z unreserved
- # 123 x7B { ext_delims
- # 124 x7C | ext_delims
- # 125 x7D } ext_delims
- # 126 x7E ~ unreserved
- # 127 x7F DEL ext_cntrl
- # 128-255 x80-FF ext_ascii
-
-
- #================================================
- # Actions used in multiple definitions
- #================================================
-
- action act_req_enc_sql { REQ(fpc, FeatureEncodeForSQL) }
-
- # REQ must apply to a char in range but not after the range has been reset
- action act_req_pathop { REQ(fpc - 1, FeaturePathOperation) }
-
- action act_clr_scheme { CLR(fpc, Scheme) }
- action act_clr_user { CLR(fpc, User) }
- action act_clr_host { CLR(fpc, Host) }
- action act_beg_host { BEG(fpc, Host) }
- action act_end_host { END(fpc, Host) }
- action act_beg_path { BEG(fpc, Path) }
- action act_end_path { END(fpc, Path) }
-
-
#================================================
- # RFC 3986 ABNFs
- #================================================
-
- DIGIT = digit;
-
- ALPHA = ( upper >{ REQ(fpc, FeatureToLower) } ) |
- lower;
-
- ALNUM = ALPHA | DIGIT;
-
- PCT = "%" >{ PctBeg(fpc); } ;
-
- HEXDIG = (
- DIGIT >{ HexDigit(fpc, fc); }
- | [A-F] >{ HexUpper(fpc, fc); }
- | [a-f] >{ HexLower(fpc, fc); }
- );
-
- # HexSet sets REQ so must apply in range
- HEXNUM = ( HEXDIG HEXDIG ) %{ HexSet(fpc - 1); };
-
- pct_encoded = PCT HEXNUM;
-
- unreserved = ALNUM | "-" | "." | "_" | "~";
-
- gen_delims = ":" | "/" | "?" | "#" | "[" | "]" | "@";
-
- sub_delims = "!" | "$" | "&" | "(" | ")"
- | "*" | "+" | "," | ";" | "="
- | ( ['] >act_req_enc_sql );
-
-
- #================================================
- # Local ABNFs
- #================================================
-
- VALID = ^(cntrl | space) | " ";
-
- # safe character sequences
- safe = unreserved | pct_encoded | sub_delims;
-
- # MOD: Yandex extensions
-
- ext_ascii = (VALID - ascii) >{ REQ(fpc, FeatureEncodeExtendedASCII) };
- ext_delims = ( "[" | "]" | "|" | "{" | "}" | "`" | "^" | "<" | ">"
- | ( ["\\] >act_req_enc_sql )
+ # RFC 3986 ABNFs
+ #================================================
+
+ DIGIT = digit;
+
+ ALPHA = ( upper >{ REQ(fpc, FeatureToLower) } ) |
+ lower;
+
+ ALNUM = ALPHA | DIGIT;
+
+ PCT = "%" >{ PctBeg(fpc); } ;
+
+ HEXDIG = (
+ DIGIT >{ HexDigit(fpc, fc); }
+ | [A-F] >{ HexUpper(fpc, fc); }
+ | [a-f] >{ HexLower(fpc, fc); }
+ );
+
+ # HexSet sets REQ so must apply in range
+ HEXNUM = ( HEXDIG HEXDIG ) %{ HexSet(fpc - 1); };
+
+ pct_encoded = PCT HEXNUM;
+
+ unreserved = ALNUM | "-" | "." | "_" | "~";
+
+ gen_delims = ":" | "/" | "?" | "#" | "[" | "]" | "@";
+
+ sub_delims = "!" | "$" | "&" | "(" | ")"
+ | "*" | "+" | "," | ";" | "="
+ | ( ['] >act_req_enc_sql );
+
+
+ #================================================
+ # Local ABNFs
+ #================================================
+
+ VALID = ^(cntrl | space) | " ";
+
+ # safe character sequences
+ safe = unreserved | pct_encoded | sub_delims;
+
+ # MOD: Yandex extensions
+
+ ext_ascii = (VALID - ascii) >{ REQ(fpc, FeatureEncodeExtendedASCII) };
+ ext_delims = ( "[" | "]" | "|" | "{" | "}" | "`" | "^" | "<" | ">"
+ | ( ["\\] >act_req_enc_sql )
) >{ REQ(fpc, FeatureEncodeExtendedDelim) }; # " fix hilite
- ext_space = " " >{ REQ(fpc, FeatureEncodeSpace) };
- ext_cntrl = cntrl >{ REQ(fpc, FeatureEncodeCntrl) };
+ ext_space = " " >{ REQ(fpc, FeatureEncodeSpace) };
+ ext_cntrl = cntrl >{ REQ(fpc, FeatureEncodeCntrl) };
pct_maybe_encoded = PCT (HEXDIG | HEXNUM)? ;
- ext_safe = unreserved
- | pct_maybe_encoded
- | sub_delims
- | ext_delims
- | ext_space
- | ext_cntrl
- | ext_ascii;
-
- # pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
- # uric (RFC 2396)
- # MOD: extension to format, add extended delimiters and 8-bit ascii
-
- pchar_nc = ext_safe | "@";
- pchar = pchar_nc | ":";
- path_sep = "/";
- uric = pchar | path_sep | "?";
-
-
- #================================================
- # Fields
- #================================================
- # Single fields use fXXX as machine definitions
-
-
- #================================================
- # Scheme
- # scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
- #================================================
-
- scheme = ( ALPHA ( ALPHA | DIGIT | "+" | "-" | "." )** );
- fscheme = scheme >{ BEG(fpc, Scheme) } %{ END(fpc, Scheme) };
-
-
- #================================================
- # UserInfo
- # userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
- #================================================
-
- # MOD: split into a pair of sections: username and password
-
- fuser = ( ext_safe )** >{ BEG(fpc, User) } %{ END(fpc, User) };
- fpass = ( ext_safe | ":" )** >{ BEG(fpc, Pass) } %{ END(fpc, Pass) };
- userinfo = ( fuser ( ":" fpass )? ) ( "@" %act_clr_host @^act_clr_user );
-
-
- #================================================
- # Hostname
- # host = IP-literal / IPv4address / reg-name
- #================================================
-
- # MOD: simplify IP-literal for now
- IPv6address = (HEXDIG | ":" | ".")+;
- IP_literal = "[" IPv6address "]";
-
- # IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
- # MOD: simplify dec-octet which originally matches only 0-255
-
- dec_octet = DIGIT+;
- IPv4address = dec_octet "." dec_octet "." dec_octet "." dec_octet;
-
+ ext_safe = unreserved
+ | pct_maybe_encoded
+ | sub_delims
+ | ext_delims
+ | ext_space
+ | ext_cntrl
+ | ext_ascii;
+
+ # pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
+ # uric (RFC 2396)
+ # MOD: extension to format, add extended delimiters and 8-bit ascii
+
+ pchar_nc = ext_safe | "@";
+ pchar = pchar_nc | ":";
+ path_sep = "/";
+ uric = pchar | path_sep | "?";
+
+
+ #================================================
+ # Fields
+ #================================================
+ # Single fields use fXXX as machine definitions
+
+
+ #================================================
+ # Scheme
+ # scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
+ #================================================
+
+ scheme = ( ALPHA ( ALPHA | DIGIT | "+" | "-" | "." )** );
+ fscheme = scheme >{ BEG(fpc, Scheme) } %{ END(fpc, Scheme) };
+
+
+ #================================================
+ # UserInfo
+ # userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
+ #================================================
+
+ # MOD: split into a pair of sections: username and password
+
+ fuser = ( ext_safe )** >{ BEG(fpc, User) } %{ END(fpc, User) };
+ fpass = ( ext_safe | ":" )** >{ BEG(fpc, Pass) } %{ END(fpc, Pass) };
+ userinfo = ( fuser ( ":" fpass )? ) ( "@" %act_clr_host @^act_clr_user );
+
+
+ #================================================
+ # Hostname
+ # host = IP-literal / IPv4address / reg-name
+ #================================================
+
+ # MOD: simplify IP-literal for now
+ IPv6address = (HEXDIG | ":" | ".")+;
+ IP_literal = "[" IPv6address "]";
+
+ # IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
+ # MOD: simplify dec-octet which originally matches only 0-255
+
+ dec_octet = DIGIT+;
+ IPv4address = dec_octet "." dec_octet "." dec_octet "." dec_octet;
+
# MOD: non-empty; will use host?
- # reg-name = *( unreserved / pct-encoded / sub-delims )
+ # reg-name = *( unreserved / pct-encoded / sub-delims )
### todo: allow ':' (need to fix grammar to disambiguate port)
achar = any - (0x00 .. 0x20) - '/' - '#' - '?' - ':' - '%';
upperhalf = any - (0x00 .. 0x7F);
hostname = (((achar | pct_encoded)+) & (any* (alnum | upperhalf) any*));
reg_name = hostname - IPv4address - IP_literal;
-
- # uses first-match-wins approach
- host = IP_literal | IPv4address | (reg_name - IPv4address);
- fhost = host? >act_beg_host %act_end_host;
- fhost_nempty = host >act_beg_host %act_end_host;
+
+ # uses first-match-wins approach
+ host = IP_literal | IPv4address | (reg_name - IPv4address);
+ fhost = host? >act_beg_host %act_end_host;
+ fhost_nempty = host >act_beg_host %act_end_host;
+
+
+ #================================================
+ # Port
+ # port = *DIGIT
+ #================================================
+
+ # MOD: use fport? for empty
+ fport = DIGIT+ >{ BEG(fpc, Port) } %{ END(fpc, Port) };
- #================================================
- # Port
- # port = *DIGIT
- #================================================
+ #================================================
+ # Authority
+ # authority = [ userinfo "@" ] host [ ":" port ]
+ #================================================
- # MOD: use fport? for empty
- fport = DIGIT+ >{ BEG(fpc, Port) } %{ END(fpc, Port) };
+ authority = userinfo? fhost ( ":" fport? )? ;
#================================================
- # Authority
- # authority = [ userinfo "@" ] host [ ":" port ]
- #================================================
-
- authority = userinfo? fhost ( ":" fport? )? ;
-
-
- #================================================
- # Path
- #================================================
- # path = path-abempty ; begins with "/" or is empty
- # / path-absolute ; begins with "/" but not "//"
- # / path-noscheme ; begins with a non-colon segment
- # / path-rootless ; begins with a segment
- # / path-empty ; zero characters
- #================================================
-
+ # Path
+ #================================================
+ # path = path-abempty ; begins with "/" or is empty
+ # / path-absolute ; begins with "/" but not "//"
+ # / path-noscheme ; begins with a non-colon segment
+ # / path-rootless ; begins with a segment
+ # / path-empty ; zero characters
+ #================================================
+
# checkPath rules
- checkPathHead =
- "." ( "."? path_sep VALID* )? %act_req_pathop ;
-
- checkPathTail =
- VALID*
- ( path_sep "."{1,2} ) %act_req_pathop ;
-
- checkPathMid = VALID*
- ( path_sep "."{,2} path_sep ) %act_req_pathop
- VALID*;
-
- checkAbsPath = checkPathMid | checkPathTail | VALID*;
- checkRelPath = checkPathHead | checkAbsPath;
-
- # segment = *pchar
- segment = pchar**;
-
- # segment-nz = 1*pchar
- segment_nz = pchar+;
-
- # segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
- segment_nz_nc = pchar_nc+;
-
- sep_segment = path_sep segment;
-
- # non-standard definitions
-
- fpath_abnempty =
- (
- ( sep_segment+ )
- & checkAbsPath
- )
- >act_beg_path %act_end_path
- ;
-
- fpath_relative =
- (
- "."
- ( "."? sep_segment+ )?
- )
- >act_beg_path %act_req_pathop %act_end_path
- ;
-
- # standard definitions
-
- # do not save empty paths, they behave differently in relative resolutions
- fpath_empty = zlen;
-
- fpath_abempty = fpath_abnempty?;
-
- fpath_absolute =
- (
- ( path_sep ( segment_nz sep_segment* )? )
- & checkAbsPath
- )
- >act_beg_path %act_end_path
- ;
-
- fpath_noscheme =
- (
- ( segment_nz_nc sep_segment* )
- & checkRelPath
- )
- >act_beg_path %act_end_path
- ;
-
- fpath_rootless =
- (
- ( segment_nz sep_segment* )
- )
- >act_beg_path %act_end_path
- ;
-
- #================================================
- # Query and fragment
- # query = *( pchar / "/" / "?" )
- # fragment = *( pchar / "/" / "?" )
- #================================================
-
- # MOD: fragment allows '#' characters
-
- fquery = (uric )** >{ BEG(fpc, Query) } %{ END(fpc, Query) };
- ffrag = (uric | "#")** >{ BEG(fpc, Frag) } %{ END(fpc, Frag) };
- query_frag = ("?" fquery)? ("#" ffrag)? ;
+ checkPathHead =
+ "." ( "."? path_sep VALID* )? %act_req_pathop ;
+
+ checkPathTail =
+ VALID*
+ ( path_sep "."{1,2} ) %act_req_pathop ;
+
+ checkPathMid = VALID*
+ ( path_sep "."{,2} path_sep ) %act_req_pathop
+ VALID*;
+
+ checkAbsPath = checkPathMid | checkPathTail | VALID*;
+ checkRelPath = checkPathHead | checkAbsPath;
+
+ # segment = *pchar
+ segment = pchar**;
+
+ # segment-nz = 1*pchar
+ segment_nz = pchar+;
+
+ # segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
+ segment_nz_nc = pchar_nc+;
+
+ sep_segment = path_sep segment;
+
+ # non-standard definitions
+
+ fpath_abnempty =
+ (
+ ( sep_segment+ )
+ & checkAbsPath
+ )
+ >act_beg_path %act_end_path
+ ;
+
+ fpath_relative =
+ (
+ "."
+ ( "."? sep_segment+ )?
+ )
+ >act_beg_path %act_req_pathop %act_end_path
+ ;
+
+ # standard definitions
+
+ # do not save empty paths, they behave differently in relative resolutions
+ fpath_empty = zlen;
+
+ fpath_abempty = fpath_abnempty?;
+
+ fpath_absolute =
+ (
+ ( path_sep ( segment_nz sep_segment* )? )
+ & checkAbsPath
+ )
+ >act_beg_path %act_end_path
+ ;
+
+ fpath_noscheme =
+ (
+ ( segment_nz_nc sep_segment* )
+ & checkRelPath
+ )
+ >act_beg_path %act_end_path
+ ;
+
+ fpath_rootless =
+ (
+ ( segment_nz sep_segment* )
+ )
+ >act_beg_path %act_end_path
+ ;
+
+ #================================================
+ # Query and fragment
+ # query = *( pchar / "/" / "?" )
+ # fragment = *( pchar / "/" / "?" )
+ #================================================
+
+ # MOD: fragment allows '#' characters
+
+ fquery = (uric )** >{ BEG(fpc, Query) } %{ END(fpc, Query) };
+ ffrag = (uric | "#")** >{ BEG(fpc, Frag) } %{ END(fpc, Frag) };
+ query_frag = ("?" fquery)? ("#" ffrag)? ;
#================================================
- # final ABNFs
- # URI-reference = URI / relative-ref
+ # final ABNFs
+ # URI-reference = URI / relative-ref
#================================================
- # URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
- # hier-part = "//" authority path-abempty
- # / path-absolute
- # / path-rootless
- # / path-empty
- # relative-ref = relative-part [ "?" query ] [ "#" fragment ]
- # relative-part = "//" authority path-abempty
- # / path-absolute
- # / path-noscheme
- # / path-empty
-
- net_path = "//" authority fpath_abempty;
-
- URI =
- fscheme ":"
- (
- net_path
- | fpath_absolute
- | fpath_rootless
- | fpath_empty
- )
- $^act_clr_scheme
- query_frag
- ;
-
- relative_ref =
- (
- net_path
- | fpath_absolute
- | fpath_noscheme
- | fpath_empty
- )
- %act_clr_scheme
- query_frag
- ;
-
- # non-standard definitions
-
- URI_no_rootless =
- fscheme ":"
- (
- net_path
- | fpath_absolute
- | fpath_empty
- )
- $^act_clr_scheme
- query_frag
- ;
-
- host_path =
- (
- fhost_nempty fpath_abempty
- | (fhost_nempty - scheme) ":" fport fpath_abempty
- )
- @^act_clr_host
- ;
-
- # no userinfo, path absolute, empty or clearly relative, starting with "./" | "../"
- relative_ref_host_pabem =
- (
- net_path
- | host_path
- | fpath_absolute
- | fpath_relative
- | fpath_empty
- )
- %act_clr_scheme
- query_frag
- ;
-
- # port must be non-empty, to avoid clash with "scheme:/..."
- auth_path =
- (
- fhost_nempty ( ":" fport )? fpath_abempty
- | userinfo fhost ( ":" fport? )? fpath_abempty
- )
- @^act_clr_host
- @^act_clr_user
- ;
-
- # userinfo, path absolute, empty or clearly relative, starting with "./" | "../"
- relative_ref_auth_pabem =
- (
- net_path
- | auth_path
- | fpath_absolute
- | fpath_relative
- | fpath_empty
- )
- %act_clr_scheme
- query_frag
- ;
-
-
- # machine instantiations
-
- URI_ref_no_rootless :=
- (
- URI_no_rootless
- # scheme://user@host preferred over user://pass@host/path
- | relative_ref_auth_pabem
- )
- ;
-
- URI_ref_no_relpath :=
- (
- relative_ref_host_pabem
- # host:port/path preferred over scheme:path/rootless
- | (URI - relative_ref_host_pabem)
- )
- ;
-
- URI_ref :=
- (
- relative_ref
- | URI
- )
- ;
-
+ # URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
+ # hier-part = "//" authority path-abempty
+ # / path-absolute
+ # / path-rootless
+ # / path-empty
+ # relative-ref = relative-part [ "?" query ] [ "#" fragment ]
+ # relative-part = "//" authority path-abempty
+ # / path-absolute
+ # / path-noscheme
+ # / path-empty
+
+ net_path = "//" authority fpath_abempty;
+
+ URI =
+ fscheme ":"
+ (
+ net_path
+ | fpath_absolute
+ | fpath_rootless
+ | fpath_empty
+ )
+ $^act_clr_scheme
+ query_frag
+ ;
+
+ relative_ref =
+ (
+ net_path
+ | fpath_absolute
+ | fpath_noscheme
+ | fpath_empty
+ )
+ %act_clr_scheme
+ query_frag
+ ;
+
+ # non-standard definitions
+
+ URI_no_rootless =
+ fscheme ":"
+ (
+ net_path
+ | fpath_absolute
+ | fpath_empty
+ )
+ $^act_clr_scheme
+ query_frag
+ ;
+
+ host_path =
+ (
+ fhost_nempty fpath_abempty
+ | (fhost_nempty - scheme) ":" fport fpath_abempty
+ )
+ @^act_clr_host
+ ;
+
+ # no userinfo, path absolute, empty or clearly relative, starting with "./" | "../"
+ relative_ref_host_pabem =
+ (
+ net_path
+ | host_path
+ | fpath_absolute
+ | fpath_relative
+ | fpath_empty
+ )
+ %act_clr_scheme
+ query_frag
+ ;
+
+ # port must be non-empty, to avoid clash with "scheme:/..."
+ auth_path =
+ (
+ fhost_nempty ( ":" fport )? fpath_abempty
+ | userinfo fhost ( ":" fport? )? fpath_abempty
+ )
+ @^act_clr_host
+ @^act_clr_user
+ ;
+
+ # userinfo, path absolute, empty or clearly relative, starting with "./" | "../"
+ relative_ref_auth_pabem =
+ (
+ net_path
+ | auth_path
+ | fpath_absolute
+ | fpath_relative
+ | fpath_empty
+ )
+ %act_clr_scheme
+ query_frag
+ ;
+
+
+ # machine instantiations
+
+ URI_ref_no_rootless :=
+ (
+ URI_no_rootless
+ # scheme://user@host preferred over user://pass@host/path
+ | relative_ref_auth_pabem
+ )
+ ;
+
+ URI_ref_no_relpath :=
+ (
+ relative_ref_host_pabem
+ # host:port/path preferred over scheme:path/rootless
+ | (URI - relative_ref_host_pabem)
+ )
+ ;
+
+ URI_ref :=
+ (
+ relative_ref
+ | URI
+ )
+ ;
+
write data;
}%%
-namespace NUri {
-
-bool TParser::doParse(const char* str_beg, size_t length)
+namespace NUri {
+
+bool TParser::doParse(const char* str_beg, size_t length)
{
const char* p = str_beg;
- const char* pe = str_beg + length;
- const char* eof = pe;
+ const char* pe = str_beg + length;
+ const char* eof = pe;
int cs;
-#define BEG(ptr, fld) startSection (ptr, TField::Field ## fld);
-#define END(ptr, fld) finishSection(ptr, TField::Field ## fld);
-#define SET(val, fld) storeSection(val, TField::Field ## fld);
-#define CLR(ptr, fld) ResetSection (TField::Field ## fld, ptr);
-#define REQ(ptr, req) setRequirement(ptr, TFeature :: req);
-
- %% write init nocs;
-
+#define BEG(ptr, fld) startSection (ptr, TField::Field ## fld);
+#define END(ptr, fld) finishSection(ptr, TField::Field ## fld);
+#define SET(val, fld) storeSection(val, TField::Field ## fld);
+#define CLR(ptr, fld) ResetSection (TField::Field ## fld, ptr);
+#define REQ(ptr, req) setRequirement(ptr, TFeature :: req);
+
+ %% write init nocs;
+
if (0 == (Flags & TFeature::FeatureNoRelPath)) {
- cs = TParser_en_URI_ref;
+ cs = TParser_en_URI_ref;
} else if (0 == (Flags & TFeature::FeatureAllowRootless)) {
- cs = TParser_en_URI_ref_no_rootless;
+ cs = TParser_en_URI_ref_no_rootless;
} else {
- cs = TParser_en_URI_ref_no_relpath;
+ cs = TParser_en_URI_ref_no_relpath;
}
-
+
%% write exec;
-#undef BEG
-#undef END
-#undef SET
-#undef CLR
-#undef REQ
-
- return cs >= TParser_first_final;
+#undef BEG
+#undef END
+#undef SET
+#undef CLR
+#undef REQ
+
+ return cs >= TParser_first_final;
+}
+
}
-
-}
diff --git a/library/cpp/uri/uri-ru_ut.cpp b/library/cpp/uri/uri-ru_ut.cpp
index 3ce98df5f4..ec35a164d2 100644
--- a/library/cpp/uri/uri-ru_ut.cpp
+++ b/library/cpp/uri/uri-ru_ut.cpp
@@ -1,9 +1,9 @@
-#include "uri_ut.h"
+#include "uri_ut.h"
#include <library/cpp/charset/recyr.hh>
#include <library/cpp/html/entity/htmlentity.h>
#include <util/system/maxlen.h>
-namespace NUri {
+namespace NUri {
namespace {
TString AsWin1251(const TString& s) {
return Recode(CODES_UTF8, CODES_WIN, s);
@@ -36,10 +36,10 @@ namespace NUri {
UNIT_ASSERT(url.IsNull(TField::FlagHost));
UNIT_ASSERT(!url.IsNull(TField::FlagPath));
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(TField::FlagPath), "www.ya.ru/index.html");
-
+
UNIT_ASSERT_VALUES_EQUAL(url.Parse(AsWin1251("www.TEST.Ru/ФЕУФ\\'\".html?ФЕУФ\\'\"=ФЕУФ+\\'\"%10")), TState::ParsedOK);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), AsWin1251("www.TEST.Ru/ФЕУФ\\'\".html?ФЕУФ\\'\"=ФЕУФ+\\'\"%10"));
-
+
UNIT_ASSERT_VALUES_EQUAL(url.Parse(AsWin1251("www.TEST.Ru/ФЕУФ\\'\".html?ФЕУФ\\'\"=ФЕУФ+\\'\"%10"),
TFeature::FeaturesDefault | TFeature::FeatureEncodeExtendedASCII),
TState::ParsedOK);
@@ -131,9 +131,9 @@ namespace NUri {
Y_UNIT_TEST(testRuIDNA) {
{
#define DEC "\xD7\xE5\xF0\xE5\xEf\xEE\xE2\xE5\xF6.\xF0\xF4" /* "Череповец.рф" in Windows-1251 */
-#define ENC "%D7%E5%F0%E5%EF%EE%E2%E5%F6.%F0%F4"
-// punycode corresponds to lowercase
-#define PNC "xn--b1afab7bff7cb.xn--p1ai"
+#define ENC "%D7%E5%F0%E5%EF%EE%E2%E5%F6.%F0%F4"
+// punycode corresponds to lowercase
+#define PNC "xn--b1afab7bff7cb.xn--p1ai"
TTest test = {
"http://" ENC "/" ENC "?" ENC "#" ENC, TParseFlags(TFeature::FeaturesAll | TFeature::FeatureAllowHostIDN, TFeature::FeatureDecodeExtendedASCII), TState::ParsedOK, "http", "", "", DEC, 80, "/" ENC, ENC, ENC};
TUri url;
@@ -141,9 +141,9 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.GetField(TField::FieldHostAscii), PNC);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" DEC "/" ENC "?" ENC "#" ENC);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(TField::FlagHostAscii), "http://" PNC "/" ENC "?" ENC "#" ENC);
-#undef PNC
-#undef DEC
-#undef ENC
+#undef PNC
+#undef DEC
+#undef ENC
}
}
@@ -158,6 +158,6 @@ namespace NUri {
// Should be properly null-terminated
UNIT_ASSERT_VALUES_EQUAL(host.size(), strlen(host.data()));
}
- }
-
+ }
+
}
diff --git a/library/cpp/uri/uri.cpp b/library/cpp/uri/uri.cpp
index d2df1ccea8..56a9a4e5ef 100644
--- a/library/cpp/uri/uri.cpp
+++ b/library/cpp/uri/uri.cpp
@@ -1,32 +1,32 @@
-#include "uri.h"
-#include "parse.h"
+#include "uri.h"
+#include "parse.h"
-#include <util/string/cast.h>
-#include <util/string/util.h>
+#include <util/string/cast.h>
+#include <util/string/util.h>
#include <util/system/yassert.h>
-namespace NUri {
+namespace NUri {
TState::EParsed TUri::CheckHost(const TStringBuf& host) {
if (host.empty())
return ParsedOK;
-
+
unsigned domainLevel = 0;
unsigned domainLevelOfUnderscore = 0;
-
+
bool isAlnum = false;
bool startLabel = true;
for (size_t i = 0; i != host.length(); ++i) {
const char ch = host[i];
-
+
if ('.' == ch) { // label separator
if (!isAlnum || startLabel) // previous label must end in alnum
return ParsedBadHost;
startLabel = true;
continue;
}
-
+
isAlnum = isalnum((const unsigned char)ch);
-
+
if (startLabel) { // label is starting
if (!isAlnum && '_' != ch) // new label must start with alnum or '_'
return ParsedBadHost;
@@ -36,7 +36,7 @@ namespace NUri {
domainLevelOfUnderscore = domainLevel;
continue;
}
-
+
if (isAlnum || '-' == ch)
continue;
@@ -46,11 +46,11 @@ namespace NUri {
}
return ParsedBadHost;
- }
-
+ }
+
if (0 < domainLevelOfUnderscore && domainLevel < 2 + domainLevelOfUnderscore)
return ParsedBadHost;
-
+
return ParsedOK;
}
@@ -65,40 +65,40 @@ namespace NUri {
if (!scheme.empty()) {
if (SetSchemeImpl(TSchemeInfo::Get(scheme)).Str.empty())
FldSet(FieldScheme, scheme);
- }
-
+ }
+
if (0 < defaultPort) // override the scheme's default port
DefaultPort = static_cast<ui16>(defaultPort);
-
+
char sport[6]; // enough for ui16
if (0 != port) {
const size_t len = ToString(port, sport, sizeof(sport));
FldSet(FieldPort, TStringBuf(sport, len));
}
-
+
FldTrySet(FieldHost, host);
FldTrySet(FieldPath, path);
FldTrySet(FieldQuery, query);
Rewrite();
- }
-
+ }
+
/********************************************************/
bool TUri::FldSetImpl(
EField field, TStringBuf value, bool strconst, bool nocopy) {
if (!FldIsValid(field))
return false;
-
+
switch (field) {
case FieldScheme:
if (!SetScheme(TSchemeInfo::Get(value)).Str.empty())
return false;
break;
-
+
case FieldPort:
Port = value.empty() ? 0 : FromString<ui16>(value);
break;
-
+
default:
break;
}
@@ -107,18 +107,18 @@ namespace NUri {
FldClr(field);
return false;
}
-
+
if (strconst) { // string constants don't need to be saved in the buffer
FldMarkClean(field);
FldSetNoDirty(field, value);
- return false;
+ return false;
}
-
+
if (nocopy) {
FldSet(field, value);
return true;
}
-
+
return FldTryCpy(field, value);
}
@@ -128,7 +128,7 @@ namespace NUri {
do {
if (!FldIsSet(field))
break;
-
+
TStringBuf& fld = Fields[field];
if (fld.length() < value.length())
break;
@@ -146,10 +146,10 @@ namespace NUri {
FldMarkDirty(field);
}
- FldSetNoDirty(field, value);
- return true;
- }
-
+ FldSetNoDirty(field, value);
+ return true;
+ }
+
/********************************************************/
void TUri::RewriteImpl() {
size_t len = 0;
@@ -169,7 +169,7 @@ namespace NUri {
const EField fld = EField(i);
if (!FldIsSet(fld))
continue;
-
+
const char* beg = out.Buf();
const TStringBuf& val = Fields[fld];
out << val;
@@ -178,12 +178,12 @@ namespace NUri {
}
Buffer = std::move(newbuf);
}
-
+
CheckMissingFields();
FieldsDirty = 0;
- }
-
+ }
+
void TUri::CheckMissingFields() {
// if host is set but path is not...
if (FldSetCmp(FlagPath | FlagHost, FlagHost))
@@ -197,7 +197,7 @@ namespace NUri {
void TUri::Merge(const TUri& base, int correctAbs) {
if (base.Scheme == SchemeUnknown)
return;
-
+
if (!base.IsValidGlobal())
return;
@@ -207,11 +207,11 @@ namespace NUri {
const bool noscheme = !selfscheme.IsInited();
if (!noscheme && !EqualNoCase(selfscheme, basescheme))
return;
-
+
const ui32 cleanFields = ~FieldsDirty;
do {
static constexpr TStringBuf rootPath = "/";
-
+
if (noscheme) {
if (!basescheme.empty()) {
FldSetNoDirty(FieldScheme, basescheme);
@@ -222,7 +222,7 @@ namespace NUri {
Scheme = base.Scheme;
DefaultPort = base.DefaultPort;
}
-
+
if (!IsNull(FlagHost))
break; // no merge
@@ -232,15 +232,15 @@ namespace NUri {
if (noscheme && IsNull(FlagQuery) && IsNull(FlagPath))
FldTrySet(FieldQuery, base);
-
+
if (IsNull(FlagAuth) && !base.IsNull(FlagAuth)) {
FldChkSet(FieldUser, base);
FldChkSet(FieldPass, base);
- }
-
+ }
+
if (IsValidAbs())
break;
-
+
TStringBuf p0 = base.GetField(FieldPath);
if (!p0.IsInited())
p0 = rootPath;
@@ -265,33 +265,33 @@ namespace NUri {
else if (p1.empty() || '.' != p1[0])
pathop = false;
out << p1;
-
+
char* beg = out.Data();
char* end = beg + out.Filled();
if (pathop && !PathOperation(beg, end, correctAbs)) {
Clear();
break;
}
-
+
// Needs immediate forced rewrite because of TTempBuf
FldSetNoDirty(FieldPath, TStringBuf(beg, end));
RewriteImpl();
} while (false);
-
+
CheckMissingFields();
-
+
// rewrite only if borrowed fields from base
if (cleanFields & FieldsDirty)
RewriteImpl();
}
-
+
/********************************************************/
TUri::TLinkType TUri::Normalize(const TUri& base,
const TStringBuf& link, const TStringBuf& codebase, long careFlags, ECharset enc) {
// parse URL
if (ParsedOK != ParseImpl(link, careFlags, 0, SchemeEmpty, enc))
return LinkIsBad;
-
+
const TStringBuf& host = GetHost();
// merge with base URL
@@ -343,7 +343,7 @@ namespace NUri {
else
len += v.length() + 1;
}
- }
+ }
}
return len;
@@ -362,7 +362,7 @@ namespace NUri {
if (!v.empty())
out << v << ':';
}
-
+
TStringBuf host;
if (flags & FlagHost) {
const EField fldhost =
@@ -373,11 +373,11 @@ namespace NUri {
TStringBuf port;
if ((flags & FlagPort) && 0 != Port && Port != DefaultPort)
port = Fields[FieldPort];
-
+
if (host) {
if (wantFlags & FlagScheme)
out << "//";
-
+
if (flags & FlagAuth) {
if (flags & FlagUser) {
v = Fields[FieldUser];
@@ -392,7 +392,7 @@ namespace NUri {
TEncoder::EncodeAll(out, v);
}
}
-
+
out << '@';
}
@@ -476,11 +476,11 @@ namespace NUri {
return false;
if (pathPtr == pathEnd)
return true;
-
+
if ((pathEnd - pathPtr) >= 2 && *(pathEnd - 2) == '/' && *(pathEnd - 1) == '.') {
--pathEnd;
}
-
+
char* p_wr = pathEnd;
int upCount = 0;
diff --git a/library/cpp/uri/uri.h b/library/cpp/uri/uri.h
index c686e0c7ea..3b6c19fe4a 100644
--- a/library/cpp/uri/uri.h
+++ b/library/cpp/uri/uri.h
@@ -1,22 +1,22 @@
#pragma once
-#include "common.h"
-#include "encode.h"
+#include "common.h"
+#include "encode.h"
#include <library/cpp/charset/doccodes.h>
#include <util/generic/buffer.h>
-#include <util/generic/ptr.h>
-#include <util/generic/singleton.h>
+#include <util/generic/ptr.h>
+#include <util/generic/singleton.h>
#include <util/generic/string.h>
-#include <util/memory/alloc.h>
+#include <util/memory/alloc.h>
#include <util/stream/mem.h>
-#include <util/stream/output.h>
+#include <util/stream/output.h>
#include <util/stream/str.h>
#include <util/system/yassert.h>
#include <cstdlib>
-namespace NUri {
+namespace NUri {
/********************************************************/
class TUri
: public TFeature,
@@ -31,7 +31,7 @@ namespace NUri {
LinkIsLocal,
LinkIsGlobal
};
-
+
private:
TBuffer Buffer;
TStringBuf Fields[FieldAllMAX];
@@ -57,7 +57,7 @@ namespace NUri {
Scheme = SchemeEmpty;
FieldsDirty = 0;
}
-
+
void CopyData(const TUri& url) {
FieldsSet = url.FieldsSet;
Port = url.Port;
@@ -65,51 +65,51 @@ namespace NUri {
Scheme = url.Scheme;
FieldsDirty = url.FieldsDirty;
}
-
+
void CopyImpl(const TUri& url) {
for (int i = 0; i < FieldAllMAX; ++i)
Fields[i] = url.Fields[i];
-
+
RewriteImpl();
}
-
+
private:
static ui32 FldFlag(EField fld) {
return 1 << fld;
}
-
+
public:
static bool FldIsValid(EField fld) {
return 0 <= fld && FieldAllMAX > fld;
}
-
+
bool FldSetCmp(ui32 chk, ui32 exp) const {
return (FieldsSet & chk) == exp;
}
-
+
bool FldSetCmp(ui32 chk) const {
return FldSetCmp(chk, chk);
}
-
+
bool FldIsSet(EField fld) const {
return !FldSetCmp(FldFlag(fld), 0);
}
-
+
private:
void FldMarkSet(EField fld) {
FieldsSet |= FldFlag(fld);
}
-
+
void FldMarkUnset(EField fld) {
FieldsSet &= ~FldFlag(fld);
}
-
+
// use when we know the field is dirty or RewriteImpl will be called
void FldSetNoDirty(EField fld, const TStringBuf& value) {
Fields[fld] = value;
FldMarkSet(fld);
}
-
+
void FldSet(EField fld, const TStringBuf& value) {
FldSetNoDirty(fld, value);
FldMarkDirty(fld);
@@ -118,7 +118,7 @@ namespace NUri {
const TStringBuf& FldGet(EField fld) const {
return Fields[fld];
}
-
+
private:
/// depending on value, clears or sets it
void FldChkSet(EField fld, const TStringBuf& value) {
@@ -130,7 +130,7 @@ namespace NUri {
void FldChkSet(EField fld, const TUri& other) {
FldChkSet(fld, other.GetField(fld));
}
-
+
/// set only if initialized
bool FldTrySet(EField fld, const TStringBuf& value) {
const bool ok = value.IsInited();
@@ -145,48 +145,48 @@ namespace NUri {
private:
/// copies the value if it fits
bool FldTryCpy(EField fld, const TStringBuf& value);
-
+
// main method: sets the field value, possibly copies, etc.
bool FldSetImpl(EField fld, TStringBuf value, bool strconst = false, bool nocopy = false);
-
+
public: // clear a field
void FldClr(EField fld) {
Fields[fld].Clear();
FldMarkUnset(fld);
FldMarkClean(fld);
}
-
+
bool FldTryClr(EField field) {
const bool ok = FldIsSet(field);
if (ok)
FldClr(field);
return ok;
}
-
+
public: // set a field value: might leave state dirty and require a Rewrite()
// copies if fits and not dirty, sets and marks dirty otherwise
bool FldMemCpy(EField field, const TStringBuf& value) {
return FldSetImpl(field, value, false);
}
-
+
// uses directly, marks dirty
/// @note client MUST guarantee value will be alive until Rewrite is called
bool FldMemSet(EField field, const TStringBuf& value) {
return FldSetImpl(field, value, false, true);
}
-
+
// uses directly, doesn't mark dirty (value scope exceeds "this")
bool FldMemUse(EField field, const TStringBuf& value) {
return FldSetImpl(field, value, true);
}
-
+
// uses directly, doesn't mark dirty
template <size_t size>
bool FldMemSet(EField field, const char (&value)[size]) {
static_assert(size > 0);
return FldSetImpl(field, TStringBuf(value, size - 1), true);
}
-
+
// duplicate one field to another
bool FldDup(EField src, EField dst) {
if (!FldIsSet(src) || !FldIsValid(dst))
@@ -198,7 +198,7 @@ namespace NUri {
FldMarkClean(dst);
return true;
}
-
+
// move one field to another
bool FldMov(EField src, EField dst) {
if (!FldDup(src, dst))
@@ -206,47 +206,47 @@ namespace NUri {
FldClr(src);
return true;
}
-
+
private:
bool IsInBuffer(const char* buf) const {
return buf >= Buffer.data() && buf < Buffer.data() + Buffer.size();
}
-
+
public:
bool FldIsDirty() const {
return 0 != FieldsDirty;
}
-
+
bool FldIsDirty(EField fld) const {
return 0 != (FieldsDirty & FldFlag(fld));
}
-
+
private:
void FldMarkDirty(EField fld) {
FieldsDirty |= FldFlag(fld);
}
-
+
void FldMarkClean(EField fld) {
FieldsDirty &= ~FldFlag(fld);
}
-
+
void RewriteImpl();
-
+
public:
static TState::EParsed CheckHost(const TStringBuf& host);
-
+
// convert a [potential] IDN to ascii
static TMallocPtr<char> IDNToAscii(const wchar32* idna);
static TMallocPtr<char> IDNToAscii(const TStringBuf& host, ECharset enc = CODES_UTF8);
-
+
// convert hosts with percent-encoded or extended chars
-
+
// returns non-empty string if host can be converted to ASCII with given parameters
static TStringBuf HostToAscii(TStringBuf host, TMallocPtr<char>& buf, bool hasExtended, bool allowIDN, ECharset enc = CODES_UTF8);
-
+
// returns host if already ascii, or non-empty if it can be converted
static TStringBuf HostToAscii(const TStringBuf& host, TMallocPtr<char>& buf, bool allowIDN, ECharset enc = CODES_UTF8);
-
+
public:
explicit TUri(unsigned defaultPort = 0)
: FieldsSet(0)
@@ -256,9 +256,9 @@ namespace NUri {
, FieldsDirty(0)
{
}
-
+
TUri(const TStringBuf& host, ui16 port, const TStringBuf& path, const TStringBuf& query = TStringBuf(), const TStringBuf& scheme = "http", unsigned defaultPort = 0);
-
+
TUri(const TUri& url)
: FieldsSet(url.FieldsSet)
, Port(url.Port)
@@ -283,8 +283,8 @@ namespace NUri {
void Clear() {
Dealloc();
ClearImpl();
- }
-
+ }
+
ui32 GetFieldMask() const {
return FieldsSet;
}
@@ -292,15 +292,15 @@ namespace NUri {
ui32 GetUrlFieldMask() const {
return GetFieldMask() & FlagUrlFields;
}
-
+
ui32 GetDirtyMask() const {
return FieldsDirty;
}
-
+
void CheckMissingFields();
-
+
// Process methods
-
+
void Rewrite() {
if (FldIsDirty())
RewriteImpl();
@@ -310,7 +310,7 @@ namespace NUri {
TState::EParsed AssignImpl(const TParser& parser, TScheme::EKind defscheme = SchemeEmpty);
TState::EParsed ParseImpl(const TStringBuf& url, const TParseFlags& flags = FeaturesDefault, ui32 maxlen = 0, TScheme::EKind defscheme = SchemeEmpty, ECharset enc = CODES_UTF8);
-
+
public:
TState::EParsed Assign(const TParser& parser, TScheme::EKind defscheme = SchemeEmpty) {
const TState::EParsed ret = AssignImpl(parser, defscheme);
@@ -318,40 +318,40 @@ namespace NUri {
Rewrite();
return ret;
}
-
+
TState::EParsed ParseUri(const TStringBuf& url, const TParseFlags& flags = FeaturesDefault, ui32 maxlen = 0, ECharset enc = CODES_UTF8) {
const TState::EParsed ret = ParseImpl(url, flags, maxlen, SchemeEmpty, enc);
if (ParsedOK == ret)
Rewrite();
return ret;
}
-
+
// parses absolute URIs
// prepends default scheme (unless unknown) if URI has none
TState::EParsed ParseAbsUri(const TStringBuf& url, const TParseFlags& flags = FeaturesDefault, ui32 maxlen = 0, TScheme::EKind defscheme = SchemeUnknown, ECharset enc = CODES_UTF8);
-
+
TState::EParsed ParseAbsOrHttpUri(const TStringBuf& url, const TParseFlags& flags = FeaturesDefault, ui32 maxlen = 0, ECharset enc = CODES_UTF8) {
return ParseAbsUri(url, flags, maxlen, SchemeHTTP, enc);
}
-
+
TState::EParsed Parse(const TStringBuf& url, const TUri& base, const TParseFlags& flags = FeaturesDefault, ui32 maxlen = 0, ECharset enc = CODES_UTF8);
-
+
TState::EParsed Parse(const TStringBuf& url, const TParseFlags& flags = FeaturesDefault) {
return ParseUri(url, flags);
}
-
+
TState::EParsed Parse(const TStringBuf& url, const TParseFlags& flags, const TStringBuf& base_url, ui32 maxlen = 0, ECharset enc = CODES_UTF8);
-
+
TState::EParsed ParseAbs(const TStringBuf& url, const TParseFlags& flags = FeaturesDefault, const TStringBuf& base_url = TStringBuf(), ui32 maxlen = 0, ECharset enc = CODES_UTF8) {
const TState::EParsed result = Parse(url, flags, base_url, maxlen, enc);
return ParsedOK != result || IsValidGlobal() ? result : ParsedBadFormat;
}
-
+
// correctAbs works with head "/.." portions:
// 1 - reject URL
// 0 - keep portions
// -1 - ignore portions
-
+
void Merge(const TUri& base, int correctAbs = -1);
TLinkType Normalize(const TUri& base, const TStringBuf& link, const TStringBuf& codebase = TStringBuf(), long careFlags = FeaturesDefault, ECharset enc = CODES_UTF8);
@@ -365,36 +365,36 @@ namespace NUri {
protected:
size_t PrintSize(ui32 flags) const;
-
+
// Output method, prints to stream
IOutputStream& PrintImpl(IOutputStream& out, int flags) const;
-
+
char* PrintImpl(char* str, size_t size, int flags) const {
TMemoryOutput out(str, size);
PrintImpl(out, flags) << '\0';
return str;
}
-
+
static bool IsAbsPath(const TStringBuf& path) {
return 1 <= path.length() && path[0] == '/';
}
-
+
bool IsAbsPathImpl() const {
return IsAbsPath(GetField(FieldPath));
}
-
+
public:
// Output method, prints to stream
IOutputStream& Print(IOutputStream& out, int flags = FlagUrlFields) const {
return PrintImpl(out, PrintFlags(flags));
}
-
+
// Output method, print to str, allocate memory if str is NULL
// Should be deprecated
char* Print(char* str, size_t size, int flags = FlagUrlFields) const {
return nullptr == str ? Serialize(flags) : Serialize(str, size, flags);
}
-
+
char* Serialize(char* str, size_t size, int flags = FlagUrlFields) const {
Y_ASSERT(str);
flags = PrintFlags(flags);
@@ -407,7 +407,7 @@ namespace NUri {
const size_t size = PrintSize(flags) + 1;
return PrintImpl(static_cast<char*>(malloc(size)), size, flags);
}
-
+
// Output method to str
void Print(TString& str, int flags = FlagUrlFields) const {
flags = PrintFlags(flags);
@@ -415,7 +415,7 @@ namespace NUri {
TStringOutput out(str);
PrintImpl(out, flags);
}
-
+
TString PrintS(int flags = FlagUrlFields) const {
TString str;
Print(str, flags);
@@ -429,7 +429,7 @@ namespace NUri {
TString PrintHostS() const {
return PrintS((Scheme != SchemeHTTP ? FlagScheme : 0) | FlagHostPort);
}
-
+
// Info methods
int Compare(const TUri& A, int flags = FlagUrlFields) const;
@@ -438,7 +438,7 @@ namespace NUri {
const TStringBuf& GetField(EField fld) const {
return FldIsValid(fld) && FldIsSet(fld) ? FldGet(fld) : Default<TStringBuf>();
}
-
+
ui16 GetPort() const {
return 0 == Port ? DefaultPort : Port;
}
@@ -454,14 +454,14 @@ namespace NUri {
bool UseHostAscii() {
return FldMov(FieldHostAscii, FieldHost);
}
-
+
TScheme::EKind GetScheme() const {
return Scheme;
}
const TSchemeInfo& GetSchemeInfo() const {
return TSchemeInfo::Get(Scheme);
}
-
+
bool IsNull(ui32 flags = FlagScheme | FlagHost | FlagPath) const {
return !FldSetCmp(flags);
}
@@ -475,7 +475,7 @@ namespace NUri {
return false;
return IsAbsPathImpl();
}
-
+
bool IsValidGlobal() const {
if (IsNull(FlagScheme | FlagHost))
return false;
@@ -492,13 +492,13 @@ namespace NUri {
bool IsOpaque() const {
return IsRootless();
}
-
+
// Inline helpers
TUri& operator=(const TUri& u) {
Copy(u);
return *this;
}
-
+
bool operator!() const {
return IsNull();
}
@@ -554,14 +554,14 @@ namespace NUri {
static IOutputStream& ReEncode(IOutputStream& out, const TStringBuf& val, long flags = FeaturesEncodeDecode) {
return ReEncodeField(out, val, FieldAllMAX, flags);
}
-
+
static int PathOperationFlag(const TParseFlags& flags) {
return flags & FeaturePathDenyRootParent ? 1
: flags & FeaturePathStripRootParent ? -1 : 0;
}
static bool PathOperation(char*& pathBeg, char*& pathEnd, int correctAbs);
-
+
private:
const TSchemeInfo& SetSchemeImpl(const TSchemeInfo& info) {
Scheme = info.Kind;
@@ -573,7 +573,7 @@ namespace NUri {
const TSchemeInfo& SetSchemeImpl(TScheme::EKind scheme) {
return SetSchemeImpl(TSchemeInfo::Get(scheme));
}
-
+
public:
const TSchemeInfo& SetScheme(const TSchemeInfo& info) {
SetSchemeImpl(info);
@@ -585,7 +585,7 @@ namespace NUri {
return SetScheme(TSchemeInfo::Get(scheme));
}
};
-
+
class TUriUpdate {
TUri& Uri_;
@@ -597,30 +597,30 @@ namespace NUri {
~TUriUpdate() {
Uri_.Rewrite();
}
-
+
public:
bool Set(TField::EField field, const TStringBuf& value) {
return Uri_.FldMemSet(field, value);
}
-
+
template <size_t size>
bool Set(TField::EField field, const char (&value)[size]) {
return Uri_.FldMemSet(field, value);
}
-
+
void Clr(TField::EField field) {
Uri_.FldClr(field);
}
};
-
+
const char* LinkTypeToString(const TUri::TLinkType& t);
-
-}
+
+}
Y_DECLARE_OUT_SPEC(inline, NUri::TUri, out, url) {
- url.Print(out);
-}
-
+ url.Print(out);
+}
+
Y_DECLARE_OUT_SPEC(inline, NUri::TUri::TLinkType, out, t) {
- out << NUri::LinkTypeToString(t);
+ out << NUri::LinkTypeToString(t);
}
diff --git a/library/cpp/uri/uri_ut.cpp b/library/cpp/uri/uri_ut.cpp
index 2a1f689e46..2ebd83fc93 100644
--- a/library/cpp/uri/uri_ut.cpp
+++ b/library/cpp/uri/uri_ut.cpp
@@ -1,11 +1,11 @@
-#include "uri_ut.h"
-#include "other.h"
+#include "uri_ut.h"
+#include "other.h"
#include "qargs.h"
#include <library/cpp/html/entity/htmlentity.h>
-#include <util/system/maxlen.h>
+#include <util/system/maxlen.h>
-namespace NUri {
+namespace NUri {
Y_UNIT_TEST_SUITE(URLTest) {
static const char* urls[] = {
"http://a/b/c/d;p?q#r",
@@ -59,7 +59,7 @@ namespace NUri {
"%20y", "http://a/b/c/%20y",
// "%2zy", "http://a/b/c/%2zy",
nullptr};
-
+
Y_UNIT_TEST(test_httpURL) {
TUri rel, base, abs;
TState::EParsed er = base.Parse(urls[0]);
@@ -90,7 +90,7 @@ namespace NUri {
UNIT_ASSERT_EQUAL_C(rel, abs, errbuf);
}
}
-
+
Y_UNIT_TEST(test_Schemes) {
TUri url;
UNIT_ASSERT_VALUES_EQUAL(url.Parse("www.ya.ru/index.html"), TState::ParsedOK);
@@ -113,7 +113,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.Parse("httpsssss://www.ya.ru", TFeature::FeaturesDefault | TFeature::FeatureSchemeFlexible), TState::ParsedOK);
UNIT_ASSERT_EQUAL(url.GetScheme(), TScheme::SchemeUnknown);
}
-
+
struct Link4Norm {
const char* const base;
const char* const link;
@@ -296,7 +296,7 @@ namespace NUri {
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "host:8080");
}
-
+
Y_UNIT_TEST(test06) {
TTest test = {
"http://user:pass@host?q", TFeature::FeaturesAll, TState::ParsedOK, "http", "user", "pass", "host", 80, "/", "q", ""};
@@ -306,7 +306,7 @@ namespace NUri {
UNIT_ASSERT(!url.FldIsDirty());
UNIT_ASSERT_VALUES_EQUAL(url.GetField(TField::FieldScheme), "https");
UNIT_ASSERT_VALUES_EQUAL(url.GetPort(), 443);
-
+
// test copying
TUri url2(url);
// make sure strings are equal...
@@ -319,13 +319,13 @@ namespace NUri {
url2.GetField(TField::FieldUser));
// and urls compare the same
URL_EQ(url, url2);
-
+
// cause a dirty field
url.FldMemSet(TField::FieldUser, "use"); // it is now shorter
UNIT_ASSERT(!url.FldIsDirty());
url.FldMemSet(TField::FieldUser, TStringBuf("user"));
UNIT_ASSERT(url.FldIsDirty());
-
+
// copy again
url2 = url;
UNIT_ASSERT(url.FldIsDirty());
@@ -340,7 +340,7 @@ namespace NUri {
url.GetField(TField::FieldUser).data(),
url2.GetField(TField::FieldUser).data());
URL_EQ(url, url2);
-
+
// make query empty
url.FldMemSet(TField::FieldQuery, "");
url2 = url;
@@ -358,7 +358,7 @@ namespace NUri {
url2.FldMemSet(TField::FieldPort, "443");
URL_EQ(url, url2);
}
-
+
Y_UNIT_TEST(test07) {
{
TTest test = {
@@ -372,7 +372,7 @@ namespace NUri {
UNIT_ASSERT_EQUAL(TScheme::SchemeHTTP, url.GetScheme());
UNIT_ASSERT_EQUAL("http", url.GetField(TField::FieldScheme));
}
-
+
{
const TString scheme = "http";
const TString host = "host.com";
@@ -384,7 +384,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), urlstr + "/");
}
}
-
+
Y_UNIT_TEST(test08) {
{
TTest test = {
@@ -471,7 +471,7 @@ namespace NUri {
URL_TEST(url, test);
}
}
-
+
Y_UNIT_TEST(test09) {
{
TTest test = {
@@ -492,7 +492,7 @@ namespace NUri {
URL_TEST(url, test);
}
}
-
+
Y_UNIT_TEST(test10) {
// test some escaping madness, note the ehost vs host
{
@@ -504,7 +504,7 @@ namespace NUri {
TUri url;
URL_TEST(url, test);
}
-
+
{
TString host = "%D0%BF%D1%80%D0%B5%D0%B7%D0%B8%D0%B4%D0%B5%D0%BD%D1%82.%D1%80%D1%84";
const TString urlstr = TString::Join("http://", host, "/");
@@ -513,7 +513,7 @@ namespace NUri {
TUri url;
URL_TEST(url, test);
}
-
+
{
TString host = "Фilip.ru";
TString ehost = "%D0%A4ilip.ru";
@@ -523,7 +523,7 @@ namespace NUri {
TUri url;
URL_TEST(url, test);
}
-
+
{
TString host = "%D0%A4ilip.ru";
const TString urlstr = TString::Join("http://", host);
@@ -532,7 +532,7 @@ namespace NUri {
TUri url;
URL_TEST(url, test);
}
-
+
{
TString host = "Filip%90.rЯ";
TString ehost = "Filip%90.r%D0%AF";
@@ -542,7 +542,7 @@ namespace NUri {
TUri url;
URL_TEST(url, test);
}
-
+
{
TString host = "Filip%90.r%D0%AF";
const TString urlstr = TString::Join(host, ":8080");
@@ -560,7 +560,7 @@ namespace NUri {
TUri url;
URL_TEST(url, test);
}
-
+
{
TTest test = {
"HtTp://HoSt/%50a%54h/?Query#Frag", TParseFlags(TFeature::FeaturesAll | TFeature::FeatureNoRelPath, TFeature::FeatureToLower), TState::ParsedOK, "http", "", "", "host", 80, "/path/", "query", "frag"};
@@ -572,62 +572,62 @@ namespace NUri {
Y_UNIT_TEST(test12) {
// test characters which are not always safe
{
-#define RAW "/:"
-#define DEC "%2F:"
-#define ENC "%2F%3A"
+#define RAW "/:"
+#define DEC "%2F:"
+#define ENC "%2F%3A"
TTest test = {
"http://" ENC ":" ENC "@host/" ENC "?" ENC "#" ENC, TFeature::FeaturesAll, TState::ParsedOK, "http", RAW, RAW, "host", 80, "/" DEC, RAW, RAW};
TUri url;
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" ENC ":" ENC "@host/" DEC "?" RAW "#" RAW);
-#undef RAW
-#undef DEC
-#undef ENC
+#undef RAW
+#undef DEC
+#undef ENC
}
{
-#define RAW "?@"
-#define DEC "%3F@"
-#define ENC "%3F%40"
+#define RAW "?@"
+#define DEC "%3F@"
+#define ENC "%3F%40"
TTest test = {
"http://" ENC ":" ENC "@host/" ENC "?" ENC "#" ENC, TFeature::FeaturesAll, TState::ParsedOK, "http", RAW, RAW, "host", 80, "/" DEC, RAW, RAW};
TUri url;
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" ENC ":" ENC "@host/" DEC "?" RAW "#" RAW);
-#undef RAW
-#undef DEC
-#undef ENC
+#undef RAW
+#undef DEC
+#undef ENC
}
{
-#define RAW "%&;="
-#define DEC "%25&;="
-#define ENC "%25%26%3B%3D"
+#define RAW "%&;="
+#define DEC "%25&;="
+#define ENC "%25%26%3B%3D"
TTest test = {
"http://" ENC ":" ENC "@host/" ENC "?" ENC "#" ENC, TFeature::FeaturesAll, TState::ParsedOK, "http", RAW, RAW, "host", 80, "/" ENC, ENC, ENC};
TUri url;
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" ENC ":" ENC "@host/" ENC "?" ENC "#" ENC);
-#undef RAW
-#undef DEC
-#undef ENC
+#undef RAW
+#undef DEC
+#undef ENC
}
{
-#define RAW "!$'()*,"
-#define DEC "!$%27()*,"
-#define ENC "%21%24%27%28%29%2A%2C"
+#define RAW "!$'()*,"
+#define DEC "!$%27()*,"
+#define ENC "%21%24%27%28%29%2A%2C"
TTest test = {
"http://" ENC ":" ENC "@host/" ENC "?" ENC "#" ENC, TFeature::FeaturesAll, TState::ParsedOK, "http", RAW, RAW, "host", 80, "/" ENC, DEC, DEC};
TUri url;
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" ENC ":" ENC "@host/" ENC "?" DEC "#" DEC);
-#undef RAW
-#undef DEC
-#undef ENC
+#undef RAW
+#undef DEC
+#undef ENC
}
{
-#define DEC "Череповец。рф"
-#define ENC "%D0%A7%D0%B5%D1%80%D0%B5%D0%BF%D0%BE%D0%B2%D0%B5%D1%86%E3%80%82%D1%80%D1%84"
-// punycode corresponds to lowercase
-#define PNC "xn--b1afab7bff7cb.xn--p1ai"
+#define DEC "Череповец。рф"
+#define ENC "%D0%A7%D0%B5%D1%80%D0%B5%D0%BF%D0%BE%D0%B2%D0%B5%D1%86%E3%80%82%D1%80%D1%84"
+// punycode corresponds to lowercase
+#define PNC "xn--b1afab7bff7cb.xn--p1ai"
TTest test = {
"http://" ENC "/" ENC "?" ENC "#" ENC, TParseFlags(TFeature::FeaturesAll | TFeature::FeatureAllowHostIDN, TFeature::FeatureDecodeExtendedASCII), TState::ParsedOK, "http", "", "", DEC, 80, "/" ENC, ENC, ENC};
TUri url;
@@ -635,23 +635,23 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.GetField(TField::FieldHostAscii), PNC);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" DEC "/" ENC "?" ENC "#" ENC);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(TField::FlagHostAscii), "http://" PNC "/" ENC "?" ENC "#" ENC);
-#undef PNC
-#undef DEC
-#undef ENC
+#undef PNC
+#undef DEC
+#undef ENC
}
{
-#define DEC "Череповец。рф"
-#define ENC "%D0%A7%D0%B5%D1%80%D0%B5%D0%BF%D0%BE%D0%B2%D0%B5%D1%86%E3%80%82%D1%80%D1%84"
-// punycode corresponds to lowercase
-#define PNC "xn--b1afab7bff7cb.xn--p1ai"
+#define DEC "Череповец。рф"
+#define ENC "%D0%A7%D0%B5%D1%80%D0%B5%D0%BF%D0%BE%D0%B2%D0%B5%D1%86%E3%80%82%D1%80%D1%84"
+// punycode corresponds to lowercase
+#define PNC "xn--b1afab7bff7cb.xn--p1ai"
TTest test = {
"http://" DEC "/" DEC "?" DEC "#" DEC, TParseFlags(TFeature::FeaturesRobot | TFeature::FeatureEncodeExtendedASCII), TState::ParsedOK, "http", "", "", PNC, 80, "/" ENC, ENC, ENC};
TUri url;
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" PNC "/" ENC "?" ENC "#" ENC);
-#undef PNC
-#undef DEC
-#undef ENC
+#undef PNC
+#undef DEC
+#undef ENC
}
{
#define DEC "независимая-экспертиза-оценка-ущерба-авто-дтп.рф"
@@ -665,7 +665,7 @@ namespace NUri {
#undef DEC
}
}
-
+
Y_UNIT_TEST(testFlexibleAuthority) {
TUri uri;
UNIT_ASSERT_EQUAL(uri.Parse("http://hello_world", TFeature::FeatureCheckHost), TState::ParsedBadHost);
@@ -728,21 +728,21 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://host/pa%thA");
}
}
-
+
Y_UNIT_TEST(testIPv6) {
{
-#define RAW "[1080:0:0:0:8:800:200C:417A]"
-#define DEC "[1080:0:0:0:8:800:200c:417a]"
+#define RAW "[1080:0:0:0:8:800:200C:417A]"
+#define DEC "[1080:0:0:0:8:800:200c:417a]"
TTest test = {
"http://" RAW "/" RAW "?" RAW "#" RAW, TParseFlags(TFeature::FeaturesAll), TState::ParsedOK, "http", "", "", DEC, 80, "/" RAW, RAW, RAW};
TUri url;
URL_TEST(url, test);
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://" DEC "/" RAW "?" RAW "#" RAW);
-#undef DEC
-#undef RAW
+#undef DEC
+#undef RAW
}
}
-
+
Y_UNIT_TEST(testEscapedFragment) {
{
TTest test = {
@@ -759,7 +759,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.PrintS(), "http://host.com/#!a=b&c=d#e+g%25");
}
}
-
+
Y_UNIT_TEST(testReEncode) {
{
TStringStream out;
@@ -767,7 +767,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(out.Str(), "foo%20bar");
}
}
-
+
static const TStringBuf NonRfcUrls[] = {
"http://deshevle.ru/price/price=&SrchTp=1&clID=24&BL=SrchTp=0|clID=24&frmID=75&SortBy=P&PreSort=&NmDir=0&VndDir=0&PrDir=0&SPP=44",
"http://secure.rollerwarehouse.com/skates/aggressive/skates/c/11[03]/tx/$$$+11[03][a-z]",
@@ -781,7 +781,7 @@ namespace NUri {
"http://www.trinity.by/?section_id=46,47,48&cat=1&filters[]=2^_^Sony",
"http://translate.yandex.net/api/v1/tr.json/translate?lang=en-ru&text=>",
nullptr};
-
+
Y_UNIT_TEST(test_NonRfcUrls) {
TUri url;
const long flags = TFeature::FeaturesRobot;
@@ -792,11 +792,11 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(TState::ParsedOK, url.Parse(buf, flags));
}
}
-
+
static const TStringBuf CheckParseException[] = {
"http://www.'>'.com/?.net/",
nullptr};
-
+
Y_UNIT_TEST(test_CheckParseException) {
TUri url;
const long flags = TFeature::FeaturesRobot | TFeature::FeaturesEncode;
@@ -816,8 +816,8 @@ namespace NUri {
}
ythrow yexception() << "failed to parse URL [" << buf << "]: " << what;
}
- }
-
+ }
+
Y_UNIT_TEST(test_PrintPort) {
TUri uri;
{
@@ -900,7 +900,7 @@ namespace NUri {
UNIT_ASSERT_VALUES_EQUAL(url.GetField(TField::FieldPath), "/path");
}
}
-
+
Y_UNIT_TEST_SUITE(TInvertDomainTest) {
Y_UNIT_TEST(TestInvert) {
TString a;
@@ -925,24 +925,24 @@ namespace NUri {
TString h("www.yandex.ru:8080/redir.pl?url=https://google.com/");
UNIT_ASSERT_EQUAL(InvertDomain(h), "ru.yandex.www:8080/redir.pl?url=https://google.com/");
}
- }
-
+ }
+
TQueryArg::EProcessed ProcessQargs(TString url, TString& processed, TQueryArgFilter filter = 0, void* filterData = 0) {
TUri uri;
uri.Parse(url, NUri::TFeature::FeaturesRecommended);
-
+
TQueryArgProcessing processing(TQueryArg::FeatureSortByName | (filter ? TQueryArg::FeatureFilter : 0) | TQueryArg::FeatureRewriteDirty, filter, filterData);
auto result = processing.Process(uri);
processed = uri.PrintS();
return result;
}
-
+
TString SortQargs(TString url) {
TString r;
ProcessQargs(url, r);
return r;
}
-
+
bool QueryArgsFilter(const TQueryArg& arg, void* filterData) {
const char* skipName = static_cast<const char*>(filterData);
return arg.Name != skipName;
diff --git a/library/cpp/uri/uri_ut.h b/library/cpp/uri/uri_ut.h
index 4df9af6283..f8ac6e4092 100644
--- a/library/cpp/uri/uri_ut.h
+++ b/library/cpp/uri/uri_ut.h
@@ -1,10 +1,10 @@
-#pragma once
-
-#include "uri.h"
-
+#pragma once
+
+#include "uri.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-namespace NUri {
+
+namespace NUri {
struct TTest {
TStringBuf Val;
TParseFlags Flags;
@@ -18,19 +18,19 @@ namespace NUri {
TStringBuf Query;
TStringBuf Frag;
};
-
-}
-
-#define URL_MSG(url1, url2, cmp) \
+
+}
+
+#define URL_MSG(url1, url2, cmp) \
(TString("[") + url1.PrintS() + ("] " cmp " [") + url2.PrintS() + "]")
-#define URL_EQ(url1, url2) \
- UNIT_ASSERT_EQUAL_C(url, url2, URL_MSG(url1, url2, "!="))
-#define URL_NEQ(url1, url2) \
- UNIT_ASSERT_UNEQUAL_C(url, url2, URL_MSG(url1, url2, "=="))
-
-#define CMP_FLD(url, test, fld) \
+#define URL_EQ(url1, url2) \
+ UNIT_ASSERT_EQUAL_C(url, url2, URL_MSG(url1, url2, "!="))
+#define URL_NEQ(url1, url2) \
+ UNIT_ASSERT_UNEQUAL_C(url, url2, URL_MSG(url1, url2, "=="))
+
+#define CMP_FLD(url, test, fld) \
UNIT_ASSERT_VALUES_EQUAL(url.GetField(TField::Field##fld), test.fld)
-
+
#define CMP_URL(url, test) \
do { \
CMP_FLD(url, test, Scheme); \
@@ -42,7 +42,7 @@ namespace NUri {
CMP_FLD(url, test, Query); \
CMP_FLD(url, test, Frag); \
} while (false)
-
+
#define URL_TEST_ENC(url, test, enc) \
do { \
TState::EParsed st = url.ParseUri(test.Val, test.Flags, 0, enc); \
@@ -76,6 +76,6 @@ namespace NUri {
CMP_URL(_url, test2); \
UNIT_ASSERT_VALUES_EQUAL(url.GetUrlFieldMask(), _url.GetUrlFieldMask()); \
} while (false)
-
-#define URL_TEST(url, test) \
- URL_TEST_ENC(url, test, CODES_UTF8)
+
+#define URL_TEST(url, test) \
+ URL_TEST_ENC(url, test, CODES_UTF8)
diff --git a/library/cpp/uri/ya.make b/library/cpp/uri/ya.make
index 03f3aa6a0f..8fc808a6af 100644
--- a/library/cpp/uri/ya.make
+++ b/library/cpp/uri/ya.make
@@ -1,30 +1,30 @@
LIBRARY()
-
+
OWNER(
mvel
g:base
)
-SRCS(
- assign.cpp
- common.cpp
- encode.cpp
+SRCS(
+ assign.cpp
+ common.cpp
+ encode.cpp
http_url.h
location.cpp
- other.cpp
- parse.cpp
+ other.cpp
+ parse.cpp
qargs.cpp
- uri.cpp
+ uri.cpp
encodefsm.rl6
parsefsm.rl6
-)
-
-PEERDIR(
- contrib/libs/libidn
+)
+
+PEERDIR(
+ contrib/libs/libidn
library/cpp/charset
-)
-
-END()
+)
+
+END()
RECURSE(
benchmark
diff --git a/library/cpp/xml/document/node-attr.h b/library/cpp/xml/document/node-attr.h
index ac9a1de64f..6e74403943 100644
--- a/library/cpp/xml/document/node-attr.h
+++ b/library/cpp/xml/document/node-attr.h
@@ -3,7 +3,7 @@
#include "xml-document-decl.h"
#include "libxml-guards.h"
#include <util/stream/str.h>
-#include <util/string/cast.h>
+#include <util/string/cast.h>
namespace NXml {
#define THROW(x, y) ythrow yexception() << #x << ": " << y
diff --git a/util/charset/wide.h b/util/charset/wide.h
index dd662373c2..04e6928aab 100644
--- a/util/charset/wide.h
+++ b/util/charset/wide.h
@@ -185,10 +185,10 @@ inline bool WriteSymbol(wchar32 s, wchar16*& dest, const wchar16* destEnd) noexc
}
inline size_t WriteSymbol(wchar32 s, wchar32*& dest) noexcept {
- *(dest++) = s;
- return 1;
-}
-
+ *(dest++) = s;
+ return 1;
+}
+
inline bool WriteSymbol(wchar32 s, wchar32*& dest, const wchar32* destEnd) noexcept {
Y_ASSERT(dest < destEnd);
@@ -299,11 +299,11 @@ namespace NDetail {
}
//! @return len if robust and position where encoding stopped if not
-template <bool robust, typename TCharType>
+template <bool robust, typename TCharType>
inline size_t UTF8ToWideImpl(const char* text, size_t len, TCharType* dest, size_t& written) noexcept {
const unsigned char* cur = reinterpret_cast<const unsigned char*>(text);
const unsigned char* last = cur + len;
- TCharType* p = dest;
+ TCharType* p = dest;
#ifdef _sse_ //can't check for sse4, as we build most of arcadia without sse4 support even on platforms that support it
if (cur + 16 <= last && NX86::CachedHaveSSE41()) {
::NDetail::UTF8ToWideImplSSE41(cur, last, p);
@@ -315,8 +315,8 @@ inline size_t UTF8ToWideImpl(const char* text, size_t len, TCharType* dest, size
return cur - reinterpret_cast<const unsigned char*>(text);
}
-template <typename TCharType>
-inline size_t UTF8ToWideImpl(const char* text, size_t len, TCharType* dest, size_t& written) {
+template <typename TCharType>
+inline size_t UTF8ToWideImpl(const char* text, size_t len, TCharType* dest, size_t& written) {
return UTF8ToWideImpl<false>(text, len, dest, written);
}
@@ -332,7 +332,7 @@ inline TUtf16String UTF8ToWide(const char* text, size_t len) {
return w;
}
-template <bool robust, typename TCharType>
+template <bool robust, typename TCharType>
inline bool UTF8ToWide(const char* text, size_t len, TCharType* dest, size_t& written) noexcept {
return UTF8ToWideImpl<robust>(text, len, dest, written) == len;
}
@@ -341,7 +341,7 @@ inline bool UTF8ToWide(const char* text, size_t len, TCharType* dest, size_t& wr
//! @attention destination buffer must be long enough to fit all characters of the text,
//! conversion stops if a broken symbol is met
//! @return @c true if all the text converted successfully, @c false - a broken symbol was found
-template <typename TCharType>
+template <typename TCharType>
inline bool UTF8ToWide(const char* text, size_t len, TCharType* dest, size_t& written) noexcept {
return UTF8ToWide<false>(text, len, dest, written);
}
@@ -659,10 +659,10 @@ inline TUtf32String ASCIIToUTF32(const TStringBuf s) {
}
//! returns @c true if string contains whitespace characters only
-inline bool IsSpace(const wchar16* s, size_t n) {
+inline bool IsSpace(const wchar16* s, size_t n) {
if (n == 0)
return false;
-
+
Y_ASSERT(s);
const wchar16* const e = s + n;
diff --git a/util/folder/dirut_ut.cpp b/util/folder/dirut_ut.cpp
index ba6a569073..45ebfc842c 100644
--- a/util/folder/dirut_ut.cpp
+++ b/util/folder/dirut_ut.cpp
@@ -70,16 +70,16 @@ Y_UNIT_TEST_SUITE(TDirutTest) {
#else
DoTest("bar", "/foo/baz", "/foo/bar");
DoTest("/foo/bar", "/bar/baz", "/foo/bar");
-
+
#ifdef NDEBUG
DoTest("bar", "./baz", "./bar");
#if 0 // should we support, for consistency, single-label dirs
DoTest("bar", "baz", "bar");
#endif
#endif
-#endif
+#endif
}
-
+
Y_UNIT_TEST(TestResolvePathRelative) {
TTempDir tempDir;
TTempBuf tempBuf;
diff --git a/util/generic/strbase.h b/util/generic/strbase.h
index e6bdf8e9b1..ab39fc7537 100644
--- a/util/generic/strbase.h
+++ b/util/generic/strbase.h
@@ -132,9 +132,9 @@ public:
}
inline size_t IterOff(const_iterator it) const noexcept {
- return begin() <= it && end() > it ? size_t(it - begin()) : npos;
- }
-
+ return begin() <= it && end() > it ? size_t(it - begin()) : npos;
+ }
+
inline const_iterator begin() const noexcept {
return Ptr();
}
@@ -197,26 +197,26 @@ public:
return !empty();
}
-public: // style-guide compliant methods
+public: // style-guide compliant methods
constexpr const TCharType* Data() const noexcept {
- return Ptr();
- }
-
+ return Ptr();
+ }
+
constexpr size_t Size() const noexcept {
- return Len();
- }
-
+ return Len();
+ }
+
Y_PURE_FUNCTION constexpr bool Empty() const noexcept {
- return 0 == Len();
- }
-
+ return 0 == Len();
+ }
+
private:
static inline TStringView LegacySubString(const TStringView view, size_t p, size_t n) noexcept {
p = Min(p, view.length());
return view.substr(p, n);
}
-public:
+public:
// ~~~ Comparison ~~~ : FAMILY0(int, compare)
static int compare(const TSelf& s1, const TSelf& s2) noexcept {
return s1.AsStringView().compare(s2.AsStringView());
@@ -469,8 +469,8 @@ public:
return npos;
}
return AsStringView().rfind(c, pos - 1);
- }
-
+ }
+
inline size_t rfind(const TStringView str, size_t pos = npos) const {
return AsStringView().rfind(str.data(), pos, str.size());
}
@@ -549,7 +549,7 @@ public:
}
inline size_t copy(TCharType* pc, size_t n, size_t pos) const {
- if (pos > Len()) {
+ if (pos > Len()) {
throw std::out_of_range("TStringBase::copy");
}
@@ -557,16 +557,16 @@ public:
}
inline size_t copy(TCharType* pc, size_t n) const noexcept {
- return CopyImpl(pc, n, 0);
+ return CopyImpl(pc, n, 0);
}
inline size_t strcpy(TCharType* pc, size_t n) const noexcept {
if (n) {
- n = copy(pc, n - 1);
- pc[n] = 0;
+ n = copy(pc, n - 1);
+ pc[n] = 0;
}
- return n;
+ return n;
}
inline TDerived copy() const Y_WARN_UNUSED_RESULT {
diff --git a/util/generic/strbuf.cpp b/util/generic/strbuf.cpp
index 2845c1e220..668602ca16 100644
--- a/util/generic/strbuf.cpp
+++ b/util/generic/strbuf.cpp
@@ -1,8 +1,8 @@
#include "strbuf.h"
-
-#include <util/stream/output.h>
+
+#include <util/stream/output.h>
#include <ostream>
-
+
std::ostream& operator<<(std::ostream& os, TStringBuf buf) {
os.write(buf.data(), buf.size());
return os;
diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h
index a794baa72d..70b9360d58 100644
--- a/util/generic/strbuf.h
+++ b/util/generic/strbuf.h
@@ -16,8 +16,8 @@ private:
using TdSelf = TBasicStringBuf;
using TBase = TStringBase<TdSelf, TCharType, TTraits>;
using TStringView = std::basic_string_view<TCharType>;
-
-public:
+
+public:
using char_type = TCharType; // TODO: DROP
using traits_type = TTraits;
@@ -99,8 +99,8 @@ public:
constexpr inline TBasicStringBuf(const TCharType* data, size_t size) noexcept
: TStringView(data, size)
- {
- }
+ {
+ }
constexpr TBasicStringBuf(const TCharType* data) noexcept
/*
@@ -108,26 +108,26 @@ public:
* while std::string_view (using std::char_traits) will abort in such case
*/
: TStringView(data, TBase::StrLen(data))
- {
- }
+ {
+ }
constexpr inline TBasicStringBuf(const TCharType* beg, const TCharType* end) noexcept
: TStringView(beg, end - beg)
{
}
-
+
template <typename D, typename T>
inline TBasicStringBuf(const TStringBase<D, TCharType, T>& str) noexcept
: TStringView(str.data(), str.size())
- {
- }
+ {
+ }
- template <typename T, typename A>
+ template <typename T, typename A>
inline TBasicStringBuf(const std::basic_string<TCharType, T, A>& str) noexcept
: TStringView(str)
- {
- }
-
+ {
+ }
+
template <typename TCharTraits>
constexpr TBasicStringBuf(std::basic_string_view<TCharType, TCharTraits> view) noexcept
: TStringView(view)
@@ -143,12 +143,12 @@ public:
*
* This means, that a class with default ctor can not be a constant member of another class with default ctor.
*/
- }
+ }
inline TBasicStringBuf(const TBasicStringBuf& src, size_t pos, size_t n) noexcept
: TBasicStringBuf(src)
{
- Skip(pos).Trunc(n);
+ Skip(pos).Trunc(n);
}
inline TBasicStringBuf(const TBasicStringBuf& src, size_t pos) noexcept
@@ -162,14 +162,14 @@ public:
return TBasicStringBuf(data() + pos, n);
}
-public:
- void Clear() {
- *this = TdSelf();
- }
-
+public:
+ void Clear() {
+ *this = TdSelf();
+ }
+
constexpr bool IsInited() const noexcept {
return data() != nullptr;
- }
+ }
public:
/**
@@ -184,8 +184,8 @@ public:
* @returns Whether the split was actually performed.
*/
inline bool TrySplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
- return TrySplitOn(TBase::find(delim), l, r);
- }
+ return TrySplitOn(TBase::find(delim), l, r);
+ }
/**
* Tries to split string in two parts using given delimiter character.
@@ -199,8 +199,8 @@ public:
* @returns Whether the split was actually performed.
*/
inline bool TryRSplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
- return TrySplitOn(TBase::rfind(delim), l, r);
- }
+ return TrySplitOn(TBase::rfind(delim), l, r);
+ }
/**
* Tries to split string in two parts using given delimiter sequence.
@@ -234,11 +234,11 @@ public:
inline void Split(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
SplitTemplate(delim, l, r);
- }
-
+ }
+
inline void RSplit(TCharType delim, TdSelf& l, TdSelf& r) const noexcept {
RSplitTemplate(delim, l, r);
- }
+ }
inline void Split(TdSelf delim, TdSelf& l, TdSelf& r) const noexcept {
SplitTemplate(delim, l, r);
@@ -249,14 +249,14 @@ public:
}
private:
- // splits on a delimiter at a given position; delimiter is excluded
+ // splits on a delimiter at a given position; delimiter is excluded
void DoSplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len) const noexcept {
Y_ASSERT(pos != TBase::npos);
- // make a copy in case one of l/r is really *this
+ // make a copy in case one of l/r is really *this
const TdSelf tok = SubStr(pos + len);
- l = Head(pos);
- r = tok;
+ l = Head(pos);
+ r = tok;
}
public:
@@ -268,39 +268,39 @@ public:
// s.TrySplitOn(s.find('z'), ...) is false, but s.TrySplitOn(100500, ...) is true.
bool TrySplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept {
- if (TBase::npos == pos)
- return false;
+ if (TBase::npos == pos)
+ return false;
DoSplitOn(pos, l, r, len);
- return true;
- }
-
+ return true;
+ }
+
void SplitOn(size_t pos, TdSelf& l, TdSelf& r, size_t len = 1) const noexcept {
if (!TrySplitOn(pos, l, r, len)) {
- l = *this;
- r = TdSelf();
+ l = *this;
+ r = TdSelf();
}
- }
+ }
bool TrySplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept {
return TrySplitOn(pos, l, r, 0);
- }
-
+ }
+
void SplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept {
SplitOn(pos, l, r, 0);
- }
-
+ }
+
/*
// Not implemented intentionally, use TrySplitOn() instead
void RSplitOn(size_t pos, TdSelf& l, TdSelf& r) const noexcept;
void RSplitAt(size_t pos, TdSelf& l, TdSelf& r) const noexcept;
*/
-
+
public:
Y_PURE_FUNCTION inline TdSelf After(TCharType c) const noexcept {
- TdSelf l, r;
+ TdSelf l, r;
return TrySplit(c, l, r) ? r : *this;
- }
+ }
Y_PURE_FUNCTION inline TdSelf Before(TCharType c) const noexcept {
TdSelf l, r;
@@ -308,10 +308,10 @@ public:
}
Y_PURE_FUNCTION inline TdSelf RAfter(TCharType c) const noexcept {
- TdSelf l, r;
+ TdSelf l, r;
return TryRSplit(c, l, r) ? r : *this;
- }
-
+ }
+
Y_PURE_FUNCTION inline TdSelf RBefore(TCharType c) const noexcept {
TdSelf l, r;
return TryRSplit(c, l, r) ? l : *this;
@@ -346,43 +346,43 @@ public:
public:
// returns tail, including pos
- TdSelf SplitOffAt(size_t pos) {
- const TdSelf tok = SubStr(pos);
- Trunc(pos);
- return tok;
- }
-
+ TdSelf SplitOffAt(size_t pos) {
+ const TdSelf tok = SubStr(pos);
+ Trunc(pos);
+ return tok;
+ }
+
// returns head, tail includes pos
- TdSelf NextTokAt(size_t pos) {
- const TdSelf tok = Head(pos);
- Skip(pos);
- return tok;
- }
-
- TdSelf SplitOffOn(size_t pos) {
- TdSelf tok;
- SplitOn(pos, *this, tok);
- return tok;
- }
-
- TdSelf NextTokOn(size_t pos) {
- TdSelf tok;
- SplitOn(pos, tok, *this);
- return tok;
- }
+ TdSelf NextTokAt(size_t pos) {
+ const TdSelf tok = Head(pos);
+ Skip(pos);
+ return tok;
+ }
+
+ TdSelf SplitOffOn(size_t pos) {
+ TdSelf tok;
+ SplitOn(pos, *this, tok);
+ return tok;
+ }
+
+ TdSelf NextTokOn(size_t pos) {
+ TdSelf tok;
+ SplitOn(pos, tok, *this);
+ return tok;
+ }
/*
// See comment on RSplitOn() above
TdSelf RSplitOffOn(size_t pos);
TdSelf RNextTokOn(size_t pos);
*/
-
+
public:
TdSelf SplitOff(TCharType delim) {
- TdSelf tok;
- Split(delim, *this, tok);
- return tok;
- }
-
+ TdSelf tok;
+ Split(delim, *this, tok);
+ return tok;
+ }
+
TdSelf RSplitOff(TCharType delim) {
TdSelf tok;
RSplit(delim, tok, *this);
@@ -419,8 +419,8 @@ public:
TdSelf NextTok(TCharType delim) {
return NextTokTemplate(delim);
- }
-
+ }
+
TdSelf RNextTok(TCharType delim) {
return RNextTokTemplate(delim);
}
@@ -433,29 +433,29 @@ public:
return RNextTokTemplate(delim);
}
-public: // string subsequences
+public: // string subsequences
/// Cut last @c shift characters (or less if length is less than @c shift)
inline TdSelf& Chop(size_t shift) noexcept {
this->remove_suffix(std::min(shift, size()));
- return *this;
- }
+ return *this;
+ }
/// Cut first @c shift characters (or less if length is less than @c shift)
inline TdSelf& Skip(size_t shift) noexcept {
this->remove_prefix(std::min(shift, size()));
- return *this;
- }
+ return *this;
+ }
/// Sets the start pointer to a position relative to the end
inline TdSelf& RSeek(size_t tailSize) noexcept {
if (size() > tailSize) {
//WARN: removing TStringView:: will lead to an infinite recursion
*this = TStringView::substr(size() - tailSize, tailSize);
- }
-
- return *this;
- }
-
+ }
+
+ return *this;
+ }
+
// coverity[exn_spec_violation]
inline TdSelf& Trunc(size_t targetSize) noexcept {
// Coverity false positive issue
@@ -463,30 +463,30 @@ public: // string subsequences
// fun_call_w_exception: Called function TStringView::substr throws an exception of type "std::out_of_range".
// Suppress this issue because we pass argument pos=0 and string_view can't throw std::out_of_range.
*this = TStringView::substr(0, targetSize); //WARN: removing TStringView:: will lead to an infinite recursion
- return *this;
- }
+ return *this;
+ }
Y_PURE_FUNCTION inline TdSelf SubStr(size_t beg) const noexcept {
- return TdSelf(*this).Skip(beg);
- }
+ return TdSelf(*this).Skip(beg);
+ }
Y_PURE_FUNCTION inline TdSelf SubStr(size_t beg, size_t len) const noexcept {
- return SubStr(beg).Trunc(len);
- }
-
+ return SubStr(beg).Trunc(len);
+ }
+
Y_PURE_FUNCTION inline TdSelf Head(size_t pos) const noexcept {
- return TdSelf(*this).Trunc(pos);
- }
-
+ return TdSelf(*this).Trunc(pos);
+ }
+
Y_PURE_FUNCTION inline TdSelf Tail(size_t pos) const noexcept {
- return SubStr(pos);
- }
-
+ return SubStr(pos);
+ }
+
Y_PURE_FUNCTION inline TdSelf Last(size_t len) const noexcept {
- return TdSelf(*this).RSeek(len);
- }
-
-private:
+ return TdSelf(*this).RSeek(len);
+ }
+
+private:
template <typename TDelimiterType>
TdSelf NextTokTemplate(TDelimiterType delim) {
TdSelf tok;
diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp
index e155946ea2..69cde785af 100644
--- a/util/generic/strbuf_ut.cpp
+++ b/util/generic/strbuf_ut.cpp
@@ -10,10 +10,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
UNIT_ASSERT_EQUAL(*str.data(), 'q');
UNIT_ASSERT_EQUAL(str.size(), 6);
-
+
TStringBuf str1("qwe\0rty"sv);
- TStringBuf str2(str1.data());
- UNIT_ASSERT_VALUES_UNEQUAL(str1, str2);
+ TStringBuf str2(str1.data());
+ UNIT_ASSERT_VALUES_UNEQUAL(str1, str2);
UNIT_ASSERT_VALUES_EQUAL(str1.size(), 7);
UNIT_ASSERT_VALUES_EQUAL(str2.size(), 3);
@@ -139,33 +139,33 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
UNIT_ASSERT(TStringBuf().empty());
UNIT_ASSERT(!TStringBuf("q").empty());
}
-
+
Y_UNIT_TEST(TestShift) {
- TStringBuf qw("qwerty");
- TStringBuf str;
-
- str = qw;
- str.Chop(10);
+ TStringBuf qw("qwerty");
+ TStringBuf str;
+
+ str = qw;
+ str.Chop(10);
UNIT_ASSERT(str.empty());
-
- str = qw;
+
+ str = qw;
UNIT_ASSERT_EQUAL(str.SubStr(2), TStringBuf("erty"));
UNIT_ASSERT_EQUAL(str.Skip(3), qw.SubStr(3));
- str.Chop(1);
+ str.Chop(1);
UNIT_ASSERT_EQUAL(str, TStringBuf("rt"));
- }
-
+ }
+
Y_UNIT_TEST(TestSplit) {
- TStringBuf qw("qwerty");
- TStringBuf lt, rt;
-
- rt = qw;
- lt = rt.NextTok('r');
+ TStringBuf qw("qwerty");
+ TStringBuf lt, rt;
+
+ rt = qw;
+ lt = rt.NextTok('r');
UNIT_ASSERT_EQUAL(lt, TStringBuf("qwe"));
UNIT_ASSERT_EQUAL(rt, TStringBuf("ty"));
-
- lt = qw;
- rt = lt.SplitOff('r');
+
+ lt = qw;
+ rt = lt.SplitOff('r');
UNIT_ASSERT_EQUAL(lt, TStringBuf("qwe"));
UNIT_ASSERT_EQUAL(rt, TStringBuf("ty"));
@@ -174,8 +174,8 @@ Y_UNIT_TEST_SUITE(TStrBufTest) {
TStringBuf ty = rt.NextTok('r'); // no 'r' in "ty"
UNIT_ASSERT_EQUAL(rt.size(), 0);
UNIT_ASSERT_EQUAL(ty, TStringBuf("ty"));
- }
-
+ }
+
Y_UNIT_TEST(TestNextTok) {
TStringBuf buf("12q45q");
TStringBuf tok;
diff --git a/util/generic/string.h b/util/generic/string.h
index 9829891afe..8cd8aa6917 100644
--- a/util/generic/string.h
+++ b/util/generic/string.h
@@ -248,7 +248,7 @@ public:
return StdStr();
#endif
- }
+ }
inline const_reference operator[](size_t pos) const noexcept {
Y_ASSERT(pos <= length());
@@ -362,8 +362,8 @@ public:
#else
return 1 == RefCount();
#endif
- }
-
+ }
+
// ~~~ Size and capacity ~~~
TBasicString& resize(size_t n, TCharType c = ' ') { // remove or append
MutRef().resize(n, c);
@@ -500,9 +500,9 @@ public:
explicit TBasicString(const TBasicStringBuf<TCharType, TTraits> s)
: TBasicString(s.data(), s.size())
- {
- }
-
+ {
+ }
+
template <typename Traits>
explicit inline TBasicString(const std::basic_string_view<TCharType, Traits>& s)
: TBasicString(s.data(), s.size())
@@ -648,12 +648,12 @@ public:
TBasicString& AssignNoAlias(const TBasicStringBuf<TCharType, TTraits> s) {
return AssignNoAlias(s.data(), s.size());
- }
-
+ }
+
TBasicString& AssignNoAlias(const TBasicStringBuf<TCharType, TTraits> s, size_t spos, size_t sn = TBase::npos) {
- return AssignNoAlias(s.SubString(spos, sn));
- }
-
+ return AssignNoAlias(s.SubString(spos, sn));
+ }
+
/**
* WARN:
* Certain invocations of this method will result in link-time error.
@@ -675,9 +675,9 @@ public:
}
TBasicString& operator=(const TBasicString& s) {
- return assign(s);
- }
-
+ return assign(s);
+ }
+
TBasicString& operator=(TBasicString&& s) noexcept {
swap(s);
return *this;
@@ -691,18 +691,18 @@ public:
}
TBasicString& operator=(const TBasicStringBuf<TCharType, TTraits> s) {
- return assign(s);
- }
-
+ return assign(s);
+ }
+
TBasicString& operator=(std::initializer_list<TCharType> il) {
return assign(il.begin(), il.end());
}
TBasicString& operator=(const TCharType* s) {
- return assign(s);
- }
+ return assign(s);
+ }
TBasicString& operator=(std::nullptr_t) = delete;
-
+
TBasicString& operator=(TExplicitType<TCharType> ch) {
return assign(ch);
}
@@ -771,20 +771,20 @@ public:
TBasicString& AppendNoAlias(const TBasicStringBuf<TCharType, TTraits> s) {
return AppendNoAlias(s.data(), s.size());
- }
-
+ }
+
TBasicString& AppendNoAlias(const TBasicStringBuf<TCharType, TTraits> s, size_t spos, size_t sn = TBase::npos) {
- return AppendNoAlias(s.SubString(spos, sn));
- }
-
+ return AppendNoAlias(s.SubString(spos, sn));
+ }
+
TBasicString& append(const TBasicStringBuf<TCharType, TTraits> s) {
return append(s.data(), s.size());
- }
-
+ }
+
TBasicString& append(const TBasicStringBuf<TCharType, TTraits> s, size_t spos, size_t sn = TBase::npos) {
- return append(s.SubString(spos, sn));
- }
-
+ return append(s.SubString(spos, sn));
+ }
+
TBasicString& append(const TCharType* pc, size_t pos, size_t n, size_t pc_len = TBase::npos) {
return append(pc + pos, Min(n, pc_len - pos));
}
@@ -882,8 +882,8 @@ public:
#endif
s1 += s2;
return std::move(s1);
- }
-
+ }
+
friend TBasicString operator+(TBasicString&& s1, const TBasicStringBuf<TCharType, TTraits> s2) Y_WARN_UNUSED_RESULT {
s1 += s2;
return std::move(s1);
@@ -968,8 +968,8 @@ public:
MutRef().insert(size_t(0), n, c);
return *this;
- }
-
+ }
+
TBasicString& prepend(TCharType c) {
MutRef().insert(size_t(0), 1, c);
@@ -977,9 +977,9 @@ public:
}
TBasicString& prepend(const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) {
- return insert(0, s, spos, sn);
- }
-
+ return insert(0, s, spos, sn);
+ }
+
// ~~~ Insertion ~~~ : FAMILY1(TBasicString&, insert, size_t pos);
TBasicString& insert(size_t pos, const TBasicString& s) {
MutRef().insert(pos, s.ConstRef());
@@ -1033,8 +1033,8 @@ public:
MutRef().insert(pos, s, spos, sn);
return *this;
- }
-
+ }
+
// ~~~ Removing ~~~
TBasicString& remove(size_t pos, size_t n) Y_NOEXCEPT {
if (pos < length()) {
@@ -1097,14 +1097,14 @@ public:
MutRef().replace(pos, n, s, len);
return *this;
- }
-
+ }
+
TBasicString& replace(size_t pos, size_t n, const TCharType* s, size_t spos, size_t sn) Y_NOEXCEPT {
MutRef().replace(pos, n, s + spos, sn - spos);
return *this;
- }
-
+ }
+
TBasicString& replace(size_t pos, size_t n1, size_t n2, TCharType c) Y_NOEXCEPT {
MutRef().replace(pos, n1, n2, c);
@@ -1113,7 +1113,7 @@ public:
TBasicString& replace(size_t pos, size_t n, const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) Y_NOEXCEPT {
MutRef().replace(pos, n, s, spos, sn);
-
+
return *this;
}
@@ -1131,7 +1131,7 @@ public:
*/
TBasicString Quote() const {
extern TBasicString EscapeC(const TBasicString&);
-
+
return TBasicString() + '"' + EscapeC(*this) + '"';
}
diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h
index 5ca96f4df1..d165bd1a06 100644
--- a/util/generic/typetraits.h
+++ b/util/generic/typetraits.h
@@ -161,7 +161,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
template <class T> \
struct THas##name \
: TBaseHas##name<T, std::is_class<T>::value || std::is_union<T>::value> {}
-
+
#define Y_HAS_MEMBER_IMPL_1(name) Y_HAS_MEMBER_IMPL_2(name, name)
/* @def Y_HAS_MEMBER
diff --git a/util/generic/yexception.h b/util/generic/yexception.h
index e73b517df5..b0c604e8c4 100644
--- a/util/generic/yexception.h
+++ b/util/generic/yexception.h
@@ -57,7 +57,7 @@ namespace NPrivateException {
}
TStringBuf AsStrBuf() const;
-
+
private:
void ZeroTerminate() noexcept;
@@ -83,9 +83,9 @@ class yexception: public NPrivateException::yexception {
};
Y_DECLARE_OUT_SPEC(inline, yexception, stream, value) {
- stream << value.AsStrBuf();
-}
-
+ stream << value.AsStrBuf();
+}
+
class TSystemError: public yexception {
public:
TSystemError(int status)
diff --git a/util/memory/tempbuf.cpp b/util/memory/tempbuf.cpp
index 17bf3e8bd3..09a2d0f140 100644
--- a/util/memory/tempbuf.cpp
+++ b/util/memory/tempbuf.cpp
@@ -36,7 +36,7 @@ public:
const void* Data() const noexcept {
return Data_;
}
-
+
inline size_t Size() const noexcept {
return Size_;
}
@@ -57,7 +57,7 @@ public:
Y_ASSERT(off <= Size());
Offset_ = off;
}
-
+
inline void Proceed(size_t off) {
Y_ASSERT(off <= Left());
@@ -225,8 +225,8 @@ char* TTempBuf::Data() noexcept {
const char* TTempBuf::Data() const noexcept {
return static_cast<const char*>(Impl_->Data());
-}
-
+}
+
size_t TTempBuf::Size() const noexcept {
return Impl_->Size();
}
@@ -251,10 +251,10 @@ void TTempBuf::Reset() noexcept {
Impl_->Reset();
}
-void TTempBuf::SetPos(size_t off) {
- Impl_->SetPos(off);
-}
-
+void TTempBuf::SetPos(size_t off) {
+ Impl_->SetPos(off);
+}
+
char* TTempBuf::Proceed(size_t off) {
char* ptr = Current();
Impl_->Proceed(off);
diff --git a/util/stream/format.h b/util/stream/format.h
index c17431f052..b033208a1b 100644
--- a/util/stream/format.h
+++ b/util/stream/format.h
@@ -114,7 +114,7 @@ namespace NFormatPrivate {
if (str[0] == '-') {
stream << '-';
str.Skip(1);
- }
+ }
if (value.Flags & HF_ADDX) {
if (Base == 16) {
@@ -130,7 +130,7 @@ namespace NFormatPrivate {
stream << str;
return stream;
- }
+ }
template <typename Char, size_t Base>
struct TBaseText {
@@ -275,11 +275,11 @@ static constexpr ::NFormatPrivate::TUnsignedBaseNumber<T, 16> Hex(const T& value
* @param value Value to output.
* @param flags Output flags.
*/
-template <typename T>
+template <typename T>
static constexpr ::NFormatPrivate::TBaseNumber<T, 16> SHex(const T& value, const ENumberFormat flags = HF_FULL | HF_ADDX) noexcept {
return {value, flags};
-}
-
+}
+
/**
* Output manipulator similar to `std::setbase(2)`.
*
diff --git a/util/stream/mem.cpp b/util/stream/mem.cpp
index a91c90a305..22a3339e27 100644
--- a/util/stream/mem.cpp
+++ b/util/stream/mem.cpp
@@ -52,11 +52,11 @@ void TMemoryOutput::DoUndo(size_t len) {
}
void TMemoryOutput::DoWrite(const void* buf, size_t len) {
- char* end = Buf_ + len;
+ char* end = Buf_ + len;
Y_ENSURE(end <= End_, TStringBuf("memory output stream exhausted"));
memcpy(Buf_, buf, len);
- Buf_ = end;
+ Buf_ = end;
}
void TMemoryOutput::DoWriteC(char c) {
diff --git a/util/stream/mem.h b/util/stream/mem.h
index 038b1bf4c1..18a5d46772 100644
--- a/util/stream/mem.h
+++ b/util/stream/mem.h
@@ -3,8 +3,8 @@
#include "zerocopy.h"
#include "zerocopy_output.h"
-#include <util/generic/strbuf.h>
-
+#include <util/generic/strbuf.h>
+
/**
* @addtogroup Streams_Memory
* @{
@@ -14,7 +14,7 @@
* Input stream that reads data from a memory block.
*/
class TMemoryInput: public IZeroCopyInputFastReadTo {
-public:
+public:
TMemoryInput() noexcept;
/**
@@ -57,31 +57,31 @@ public:
* @param len Size of the new memory block.
*/
void Reset(const void* buf, size_t len) noexcept {
- Buf_ = (const char*)buf;
- Len_ = len;
- }
+ Buf_ = (const char*)buf;
+ Len_ = len;
+ }
/**
* @returns Whether there is more data in the stream.
*/
bool Exhausted() const noexcept {
- return !Avail();
- }
+ return !Avail();
+ }
/**
* @returns Number of bytes available in the stream.
*/
size_t Avail() const noexcept {
- return Len_;
- }
+ return Len_;
+ }
/**
* @returns Current read position in the memory block
* used by this stream.
*/
const char* Buf() const noexcept {
- return Buf_;
- }
+ return Buf_;
+ }
/**
* Initializes this stream with a next chunk extracted from the given zero
@@ -94,22 +94,22 @@ public:
if (!Len_) {
Reset(nullptr, 0);
}
- }
+ }
-private:
+private:
size_t DoNext(const void** ptr, size_t len) override;
void DoUndo(size_t len) override;
-private:
- const char* Buf_;
- size_t Len_;
+private:
+ const char* Buf_;
+ size_t Len_;
};
/**
* Output stream that writes data to a memory block.
*/
class TMemoryOutput: public IZeroCopyOutput {
-public:
+public:
/**
* Constructs a stream that writes to the provided memory block. It's up
* to the user to make sure that the memory block doesn't get freed while
@@ -138,50 +138,50 @@ public:
*/
inline void Reset(void* buf, size_t len) noexcept {
Buf_ = static_cast<char*>(buf);
- End_ = Buf_ + len;
- }
+ End_ = Buf_ + len;
+ }
/**
* @returns Whether there is more space in the
* stream for writing.
*/
inline bool Exhausted() const noexcept {
- return !Avail();
- }
+ return !Avail();
+ }
/**
* @returns Number of bytes available for writing
* in the stream.
*/
inline size_t Avail() const noexcept {
- return End_ - Buf_;
- }
+ return End_ - Buf_;
+ }
/**
* @returns Current write position in the memory block
* used by this stream.
*/
inline char* Buf() const noexcept {
- return Buf_;
- }
+ return Buf_;
+ }
/**
* @returns Pointer to the end of the memory block
* used by this stream.
*/
- char* End() const {
- return End_;
- }
-
-private:
+ char* End() const {
+ return End_;
+ }
+
+private:
size_t DoNext(void** ptr) override;
void DoUndo(size_t len) override;
void DoWrite(const void* buf, size_t len) override;
void DoWriteC(char c) override;
-protected:
- char* Buf_;
- char* End_;
+protected:
+ char* Buf_;
+ char* End_;
};
/**
@@ -191,65 +191,65 @@ protected:
* @see TMemoryOutput
*/
class TMemoryWriteBuffer: public TMemoryOutput {
-public:
- TMemoryWriteBuffer(void* buf, size_t len)
- : TMemoryOutput(buf, len)
- , Beg_(Buf_)
+public:
+ TMemoryWriteBuffer(void* buf, size_t len)
+ : TMemoryOutput(buf, len)
+ , Beg_(Buf_)
{
}
-
- void Reset(void* buf, size_t len) {
- TMemoryOutput::Reset(buf, len);
- Beg_ = Buf_;
- }
-
- size_t Len() const {
- return Buf() - Beg();
- }
-
- size_t Empty() const {
- return Buf() == Beg();
- }
-
+
+ void Reset(void* buf, size_t len) {
+ TMemoryOutput::Reset(buf, len);
+ Beg_ = Buf_;
+ }
+
+ size_t Len() const {
+ return Buf() - Beg();
+ }
+
+ size_t Empty() const {
+ return Buf() == Beg();
+ }
+
/**
* @returns Data that has been written into this
* stream as a string.
*/
- TStringBuf Str() const {
- return TStringBuf(Beg(), Buf());
- }
-
- char* Beg() const {
- return Beg_;
- }
-
+ TStringBuf Str() const {
+ return TStringBuf(Beg(), Buf());
+ }
+
+ char* Beg() const {
+ return Beg_;
+ }
+
/**
* @param ptr New write position for this stream.
* Must be inside the memory block that
* this stream uses.
*/
- void SetPos(char* ptr) {
+ void SetPos(char* ptr) {
Y_ASSERT(Beg_ <= ptr);
- SetPosImpl(ptr);
- }
-
+ SetPosImpl(ptr);
+ }
+
/**
* @param pos New write position for this stream,
* relative to the beginning of the memory
* block that this stream uses.
*/
- void SetPos(size_t pos) {
- SetPosImpl(Beg_ + pos);
- }
-
-protected:
- void SetPosImpl(char* ptr) {
+ void SetPos(size_t pos) {
+ SetPosImpl(Beg_ + pos);
+ }
+
+protected:
+ void SetPosImpl(char* ptr) {
Y_ASSERT(End_ >= ptr);
- Buf_ = ptr;
- }
-
-protected:
- char* Beg_;
-};
-
+ Buf_ = ptr;
+ }
+
+protected:
+ char* Beg_;
+};
+
/** @} */
diff --git a/util/stream/output.h b/util/stream/output.h
index 8a2f209116..00eef50b95 100644
--- a/util/stream/output.h
+++ b/util/stream/output.h
@@ -82,7 +82,7 @@ public:
inline void Write(const TStringBuf st) {
Write(st.data(), st.size());
}
-
+
/**
* Writes several data blocks into this stream.
*
@@ -191,7 +191,7 @@ void Out(IOutputStream& out, typename TTypeTraits<T>::TFuncParam value);
#define Y_DECLARE_OUT_SPEC(MODIF, T, stream, value) \
template <> \
MODIF void Out<T>(IOutputStream & stream, TTypeTraits<T>::TFuncParam value)
-
+
template <>
inline void Out<const char*>(IOutputStream& o, const char* t) {
if (t) {
diff --git a/util/string/util.h b/util/string/util.h
index b42a5f2050..0d77a5042b 100644
--- a/util/string/util.h
+++ b/util/string/util.h
@@ -102,19 +102,19 @@ public:
return cbrk(s) - s;
}
- size_t spn(const char* s, const char* e) const {
- return cbrk(s, e) - s;
- }
-
+ size_t spn(const char* s, const char* e) const {
+ return cbrk(s, e) - s;
+ }
+
/// Offset of the first character in table, like strcspn().
size_t cspn(const char* s) const {
return brk(s) - s;
}
- size_t cspn(const char* s, const char* e) const {
- return brk(s, e) - s;
- }
-
+ size_t cspn(const char* s, const char* e) const {
+ return brk(s, e) - s;
+ }
+
char* brk(char* s) const {
return const_cast<char*>(brk((const char*)s));
}
diff --git a/util/system/atomic_ut.cpp b/util/system/atomic_ut.cpp
index a0a0d60608..07211ffba7 100644
--- a/util/system/atomic_ut.cpp
+++ b/util/system/atomic_ut.cpp
@@ -4,10 +4,10 @@
#include <util/generic/ylimits.h>
-template <typename TAtomic>
-class TAtomicTest
+template <typename TAtomic>
+class TAtomicTest
: public TTestBase {
- UNIT_TEST_SUITE(TAtomicTest);
+ UNIT_TEST_SUITE(TAtomicTest);
UNIT_TEST(TestAtomicInc1)
UNIT_TEST(TestAtomicInc2)
UNIT_TEST(TestAtomicGetAndInc)
@@ -24,30 +24,30 @@ class TAtomicTest
UNIT_TEST(TestCAS)
UNIT_TEST(TestGetAndCAS)
UNIT_TEST(TestLockUnlock)
- UNIT_TEST_SUITE_END();
-
-private:
- inline void TestLockUnlock() {
- TAtomic v = 0;
-
- UNIT_ASSERT(AtomicTryLock(&v));
- UNIT_ASSERT(!AtomicTryLock(&v));
- UNIT_ASSERT_VALUES_EQUAL(v, 1);
- AtomicUnlock(&v);
- UNIT_ASSERT_VALUES_EQUAL(v, 0);
- }
-
- inline void TestCAS() {
- TAtomic v = 0;
-
- UNIT_ASSERT(AtomicCas(&v, 1, 0));
- UNIT_ASSERT(!AtomicCas(&v, 1, 0));
- UNIT_ASSERT_VALUES_EQUAL(v, 1);
- UNIT_ASSERT(AtomicCas(&v, 0, 1));
- UNIT_ASSERT_VALUES_EQUAL(v, 0);
- UNIT_ASSERT(AtomicCas(&v, Max<intptr_t>(), 0));
- UNIT_ASSERT_VALUES_EQUAL(v, Max<intptr_t>());
- }
+ UNIT_TEST_SUITE_END();
+
+private:
+ inline void TestLockUnlock() {
+ TAtomic v = 0;
+
+ UNIT_ASSERT(AtomicTryLock(&v));
+ UNIT_ASSERT(!AtomicTryLock(&v));
+ UNIT_ASSERT_VALUES_EQUAL(v, 1);
+ AtomicUnlock(&v);
+ UNIT_ASSERT_VALUES_EQUAL(v, 0);
+ }
+
+ inline void TestCAS() {
+ TAtomic v = 0;
+
+ UNIT_ASSERT(AtomicCas(&v, 1, 0));
+ UNIT_ASSERT(!AtomicCas(&v, 1, 0));
+ UNIT_ASSERT_VALUES_EQUAL(v, 1);
+ UNIT_ASSERT(AtomicCas(&v, 0, 1));
+ UNIT_ASSERT_VALUES_EQUAL(v, 0);
+ UNIT_ASSERT(AtomicCas(&v, Max<intptr_t>(), 0));
+ UNIT_ASSERT_VALUES_EQUAL(v, Max<intptr_t>());
+ }
inline void TestGetAndCAS() {
TAtomic v = 0;
@@ -61,23 +61,23 @@ private:
UNIT_ASSERT_VALUES_EQUAL(v, Max<intptr_t>());
}
- inline void TestAtomicInc1() {
- TAtomic v = 0;
+ inline void TestAtomicInc1() {
+ TAtomic v = 0;
- UNIT_ASSERT(AtomicAdd(v, 1));
- UNIT_ASSERT_VALUES_EQUAL(v, 1);
- UNIT_ASSERT(AtomicAdd(v, 10));
- UNIT_ASSERT_VALUES_EQUAL(v, 11);
- }
+ UNIT_ASSERT(AtomicAdd(v, 1));
+ UNIT_ASSERT_VALUES_EQUAL(v, 1);
+ UNIT_ASSERT(AtomicAdd(v, 10));
+ UNIT_ASSERT_VALUES_EQUAL(v, 11);
+ }
- inline void TestAtomicInc2() {
- TAtomic v = 0;
+ inline void TestAtomicInc2() {
+ TAtomic v = 0;
- UNIT_ASSERT(AtomicIncrement(v));
- UNIT_ASSERT_VALUES_EQUAL(v, 1);
- UNIT_ASSERT(AtomicIncrement(v));
- UNIT_ASSERT_VALUES_EQUAL(v, 2);
- }
+ UNIT_ASSERT(AtomicIncrement(v));
+ UNIT_ASSERT_VALUES_EQUAL(v, 1);
+ UNIT_ASSERT(AtomicIncrement(v));
+ UNIT_ASSERT_VALUES_EQUAL(v, 2);
+ }
inline void TestAtomicGetAndInc() {
TAtomic v = 0;
@@ -88,14 +88,14 @@ private:
UNIT_ASSERT_VALUES_EQUAL(v, 2);
}
- inline void TestAtomicDec() {
- TAtomic v = 2;
+ inline void TestAtomicDec() {
+ TAtomic v = 2;
- UNIT_ASSERT(AtomicDecrement(v));
- UNIT_ASSERT_VALUES_EQUAL(v, 1);
- UNIT_ASSERT(!AtomicDecrement(v));
- UNIT_ASSERT_VALUES_EQUAL(v, 0);
- }
+ UNIT_ASSERT(AtomicDecrement(v));
+ UNIT_ASSERT_VALUES_EQUAL(v, 1);
+ UNIT_ASSERT(!AtomicDecrement(v));
+ UNIT_ASSERT_VALUES_EQUAL(v, 0);
+ }
inline void TestAtomicGetAndDec() {
TAtomic v = 2;
@@ -106,15 +106,15 @@ private:
UNIT_ASSERT_VALUES_EQUAL(v, 0);
}
- inline void TestAtomicAdd() {
- TAtomic v = 0;
+ inline void TestAtomicAdd() {
+ TAtomic v = 0;
+
+ UNIT_ASSERT_VALUES_EQUAL(AtomicAdd(v, 1), 1);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicAdd(v, 2), 3);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicAdd(v, -4), -1);
+ UNIT_ASSERT_VALUES_EQUAL(v, -1);
+ }
- UNIT_ASSERT_VALUES_EQUAL(AtomicAdd(v, 1), 1);
- UNIT_ASSERT_VALUES_EQUAL(AtomicAdd(v, 2), 3);
- UNIT_ASSERT_VALUES_EQUAL(AtomicAdd(v, -4), -1);
- UNIT_ASSERT_VALUES_EQUAL(v, -1);
- }
-
inline void TestAtomicGetAndAdd() {
TAtomic v = 0;
@@ -125,13 +125,13 @@ private:
}
inline void TestAtomicSub() {
- TAtomic v = 4;
+ TAtomic v = 4;
- UNIT_ASSERT_VALUES_EQUAL(AtomicSub(v, 1), 3);
- UNIT_ASSERT_VALUES_EQUAL(AtomicSub(v, 2), 1);
- UNIT_ASSERT_VALUES_EQUAL(AtomicSub(v, 3), -2);
- UNIT_ASSERT_VALUES_EQUAL(v, -2);
- }
+ UNIT_ASSERT_VALUES_EQUAL(AtomicSub(v, 1), 3);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicSub(v, 2), 1);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicSub(v, 3), -2);
+ UNIT_ASSERT_VALUES_EQUAL(v, -2);
+ }
inline void TestAtomicGetAndSub() {
TAtomic v = 4;
@@ -142,15 +142,15 @@ private:
UNIT_ASSERT_VALUES_EQUAL(v, -2);
}
- inline void TestAtomicSwap() {
- TAtomic v = 0;
+ inline void TestAtomicSwap() {
+ TAtomic v = 0;
UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, 3), 0);
UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, 5), 3);
UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, -7), 5);
UNIT_ASSERT_VALUES_EQUAL(AtomicSwap(&v, Max<intptr_t>()), -7);
- UNIT_ASSERT_VALUES_EQUAL(v, Max<intptr_t>());
- }
+ UNIT_ASSERT_VALUES_EQUAL(v, Max<intptr_t>());
+ }
inline void TestAtomicOr() {
TAtomic v = 0xf0;
@@ -191,26 +191,26 @@ private:
UNIT_TEST_SUITE_REGISTRATION(TAtomicTest<TAtomic>);
#ifndef _MSC_VER
-// chooses type *other than* T1
+// chooses type *other than* T1
template <typename T1, typename T2, typename T3>
struct TChooser {
using TdType = T2;
-};
+};
template <typename T1, typename T2>
struct TChooser<T1, T1, T2> {
using TdType = T2;
-};
+};
template <typename T1>
struct TChooser<T1, T1, T1> {};
-
+
#if defined(__IOS__) && defined(_32_)
using TAltAtomic = int;
#else
using TAltAtomic = volatile TChooser<TAtomicBase, long, long long>::TdType;
#endif
-
+
class TTTest: public TAtomicTest<TAltAtomic> {
public:
TString Name() const noexcept override {
diff --git a/util/system/cpu_id.cpp b/util/system/cpu_id.cpp
index 0ae06b2868..598c71f4d9 100644
--- a/util/system/cpu_id.cpp
+++ b/util/system/cpu_id.cpp
@@ -60,8 +60,8 @@ bool NX86::CpuId(ui32 op, ui32* res) noexcept {
return false;
#endif
-}
-
+}
+
namespace {
union TX86CpuInfo {
ui32 Info[4];
@@ -80,11 +80,11 @@ namespace {
inline TX86CpuInfo(ui32 op, ui32 subOp) noexcept {
NX86::CpuId(op, subOp, Info);
}
- };
+ };
static_assert(sizeof(TX86CpuInfo) == 16, "please, fix me");
}
-
+
// https://en.wikipedia.org/wiki/CPUID
bool NX86::HaveRDTSCP() noexcept {
return (TX86CpuInfo(0x80000001).EDX >> 27) & 1u;
@@ -96,8 +96,8 @@ bool NX86::HaveSSE() noexcept {
bool NX86::HaveSSE2() noexcept {
return (TX86CpuInfo(0x1).EDX >> 26) & 1u;
-}
-
+}
+
bool NX86::HaveSSE3() noexcept {
return TX86CpuInfo(0x1).ECX & 1u;
}
@@ -116,8 +116,8 @@ bool NX86::HaveSSE41() noexcept {
bool NX86::HaveSSE42() noexcept {
return (TX86CpuInfo(0x1).ECX >> 20) & 1u;
-}
-
+}
+
bool NX86::HaveF16C() noexcept {
return (TX86CpuInfo(0x1).ECX >> 29) & 1u;
}
@@ -253,7 +253,7 @@ const char* CpuBrand(ui32* store) noexcept {
#endif
return (const char*)store;
-}
+}
#define Y_DEF_NAME(X) \
bool NX86::CachedHave##X() noexcept { \
diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp
index 4e8ada2d9a..941e6a50f3 100644
--- a/util/system/file_ut.cpp
+++ b/util/system/file_ut.cpp
@@ -175,7 +175,7 @@ void TFileTest::TestRW() {
f1.Flush();
ui32 v;
f1.Load(&v, sizeof(v));
- UNIT_ASSERT_VALUES_EQUAL(v, 3u);
+ UNIT_ASSERT_VALUES_EQUAL(v, 3u);
UNIT_ASSERT_VALUES_EQUAL(f1.GetPosition(), 16);
TFile f2 = f1;
@@ -189,7 +189,7 @@ void TFileTest::TestRW() {
UNIT_ASSERT_VALUES_EQUAL(f1.Seek(-4, sCur), 16);
v = 0;
f1.Load(&v, sizeof(v));
- UNIT_ASSERT_VALUES_EQUAL(v, 3u);
+ UNIT_ASSERT_VALUES_EQUAL(v, 3u);
f1.Close();
UNIT_ASSERT(!f1.IsOpen());
UNIT_ASSERT(!f2.IsOpen());
diff --git a/util/system/maxlen.h b/util/system/maxlen.h
index 49efad8a23..e1ff7f5008 100644
--- a/util/system/maxlen.h
+++ b/util/system/maxlen.h
@@ -2,11 +2,11 @@
#include <cstdlib>
-// http://support.microsoft.com/kb/208427
-#ifndef URL_MAXLEN
+// http://support.microsoft.com/kb/208427
+#ifndef URL_MAXLEN
#define URL_MAXLEN 2083
-#endif
-
+#endif
+
#define HOST_MAX 260
#ifndef URL_MAX
#define URL_MAX 1024
diff --git a/util/system/platform.h b/util/system/platform.h
index 512d940123..58f310ab34 100644
--- a/util/system/platform.h
+++ b/util/system/platform.h
@@ -240,7 +240,7 @@
#define SIZEOF_LONG_LONG 8
#define SIZEOF_UNSIGNED_LONG_LONG 8
-#undef SIZEOF_SIZE_T // in case we include <Python.h> which defines it, too
+#undef SIZEOF_SIZE_T // in case we include <Python.h> which defines it, too
#define SIZEOF_SIZE_T SIZEOF_PTR
// clang-format on
diff --git a/util/system/tls.h b/util/system/tls.h
index b42508143c..3c4f56dbeb 100644
--- a/util/system/tls.h
+++ b/util/system/tls.h
@@ -178,42 +178,42 @@ namespace NTls {
template <class T>
class TValue: public TMoveOnly {
- class TConstructor {
- public:
+ class TConstructor {
+ public:
TConstructor() noexcept = default;
virtual ~TConstructor() = default;
- virtual T* Construct(void* ptr) const = 0;
- };
+ virtual T* Construct(void* ptr) const = 0;
+ };
- class TDefaultConstructor: public TConstructor {
- public:
+ class TDefaultConstructor: public TConstructor {
+ public:
~TDefaultConstructor() override = default;
T* Construct(void* ptr) const override {
//memset(ptr, 0, sizeof(T));
return ::new (ptr) T();
- }
- };
+ }
+ };
- template <class T1>
- class TCopyConstructor: public TConstructor {
- public:
- inline TCopyConstructor(const T1& value)
- : Value(value)
- {
- }
+ template <class T1>
+ class TCopyConstructor: public TConstructor {
+ public:
+ inline TCopyConstructor(const T1& value)
+ : Value(value)
+ {
+ }
~TCopyConstructor() override = default;
T* Construct(void* ptr) const override {
return ::new (ptr) T(Value);
- }
+ }
- private:
- T1 Value;
- };
+ private:
+ T1 Value;
+ };
public:
inline TValue()
@@ -239,30 +239,30 @@ namespace NTls {
}
inline operator T&() {
- return Get();
- }
-
+ return Get();
+ }
+
inline const T& operator->() const {
return Get();
}
- inline T& operator->() {
- return Get();
- }
-
- inline const T* operator&() const {
- return GetPtr();
- }
-
- inline T* operator&() {
- return GetPtr();
- }
-
+ inline T& operator->() {
+ return Get();
+ }
+
+ inline const T* operator&() const {
+ return GetPtr();
+ }
+
+ inline T* operator&() {
+ return GetPtr();
+ }
+
inline T& Get() const {
- return *GetPtr();
- }
-
- inline T* GetPtr() const {
+ return *GetPtr();
+ }
+
+ inline T* GetPtr() const {
T* val = static_cast<T*>(Key_.Get());
if (!val) {
@@ -274,7 +274,7 @@ namespace NTls {
val = newval.Release();
}
- return val;
+ return val;
}
private: