MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Parse

Function Parse

Source/ThirdParty/rapidjson/pointer.h:930–1060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

928 */
929#endif
930 void Parse(const Ch* source, size_t length) {
931 RAPIDJSON_ASSERT(source != NULL);
932 RAPIDJSON_ASSERT(nameBuffer_ == 0);
933 RAPIDJSON_ASSERT(tokens_ == 0);
934
935 // Create own allocator if user did not supply.
936 if (!allocator_)
937 ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
938
939 // Count number of '/' as tokenCount
940 tokenCount_ = 0;
941 for (const Ch* s = source; s != source + length; s++)
942 if (*s == '/')
943 tokenCount_++;
944
945 Token* token = tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ * sizeof(Token) + length * sizeof(Ch)));
946 Ch* name = nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
947 size_t i = 0;
948
949 // Detect if it is a URI fragment
950 bool uriFragment = false;
951 if (source[i] == '#') {
952 uriFragment = true;
953 i++;
954 }
955
956 if (i != length && source[i] != '/') {
957 parseErrorCode_ = kPointerParseErrorTokenMustBeginWithSolidus;
958 goto error;
959 }
960
961 while (i < length) {
962 RAPIDJSON_ASSERT(source[i] == '/');
963 i++; // consumes '/'
964
965 token->name = name;
966 bool isNumber = true;
967
968 while (i < length && source[i] != '/') {
969 Ch c = source[i];
970 if (uriFragment) {
971 // Decoding percent-encoding for URI fragment
972 if (c == '%') {
973 PercentDecodeStream is(&source[i], source + length);
974 GenericInsituStringStream<EncodingType> os(name);
975 Ch* begin = os.PutBegin();
976 if (!Transcoder<UTF8<>, EncodingType>().Validate(is, os) || !is.IsValid()) {
977 parseErrorCode_ = kPointerParseErrorInvalidPercentEncoding;
978 goto error;
979 }
980 size_t len = os.PutEnd(begin);
981 i += is.Tell() - 1;
982 if (len == 1)
983 c = *name;
984 else {
985 name += len;
986 isNumber = false;
987 i++;

Callers 1

GenericPointerMethod · 0.70

Calls 8

NeedPercentEncodeFunction · 0.85
FreeFunction · 0.70
MallocMethod · 0.45
PutBeginMethod · 0.45
ValidateMethod · 0.45
IsValidMethod · 0.45
PutEndMethod · 0.45
TellMethod · 0.45

Tested by

no test coverage detected