OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/policy/core/common/schema.h" | 5 #include "components/policy/core/common/schema.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // pointer. | 64 // pointer. |
65 const int kInvalid = -1; | 65 const int kInvalid = -1; |
66 | 66 |
67 bool SchemaTypeToValueType(const std::string& type_string, | 67 bool SchemaTypeToValueType(const std::string& type_string, |
68 base::Value::Type* type) { | 68 base::Value::Type* type) { |
69 // Note: "any" is not an accepted type. | 69 // Note: "any" is not an accepted type. |
70 static const struct { | 70 static const struct { |
71 const char* schema_type; | 71 const char* schema_type; |
72 base::Value::Type value_type; | 72 base::Value::Type value_type; |
73 } kSchemaToValueTypeMap[] = { | 73 } kSchemaToValueTypeMap[] = { |
74 { schema::kArray, base::Value::TYPE_LIST }, | 74 { schema::kArray, base::Value::Type::LIST }, |
75 { schema::kBoolean, base::Value::TYPE_BOOLEAN }, | 75 { schema::kBoolean, base::Value::Type::BOOLEAN }, |
76 { schema::kInteger, base::Value::TYPE_INTEGER }, | 76 { schema::kInteger, base::Value::Type::INTEGER }, |
77 { schema::kNull, base::Value::TYPE_NULL }, | 77 { schema::kNull, base::Value::Type::NONE }, |
78 { schema::kNumber, base::Value::TYPE_DOUBLE }, | 78 { schema::kNumber, base::Value::Type::DOUBLE }, |
79 { schema::kObject, base::Value::TYPE_DICTIONARY }, | 79 { schema::kObject, base::Value::Type::DICTIONARY }, |
80 { schema::kString, base::Value::TYPE_STRING }, | 80 { schema::kString, base::Value::Type::STRING }, |
81 }; | 81 }; |
82 for (size_t i = 0; i < arraysize(kSchemaToValueTypeMap); ++i) { | 82 for (size_t i = 0; i < arraysize(kSchemaToValueTypeMap); ++i) { |
83 if (kSchemaToValueTypeMap[i].schema_type == type_string) { | 83 if (kSchemaToValueTypeMap[i].schema_type == type_string) { |
84 *type = kSchemaToValueTypeMap[i].value_type; | 84 *type = kSchemaToValueTypeMap[i].value_type; |
85 return true; | 85 return true; |
86 } | 86 } |
87 } | 87 } |
88 return false; | 88 return false; |
89 } | 89 } |
90 | 90 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 void Schema::InternalStorage::DetermineStorageSizes( | 359 void Schema::InternalStorage::DetermineStorageSizes( |
360 const base::DictionaryValue& schema, | 360 const base::DictionaryValue& schema, |
361 StorageSizes* sizes) { | 361 StorageSizes* sizes) { |
362 std::string ref_string; | 362 std::string ref_string; |
363 if (schema.GetString(schema::kRef, &ref_string)) { | 363 if (schema.GetString(schema::kRef, &ref_string)) { |
364 // Schemas with a "$ref" attribute don't take additional storage. | 364 // Schemas with a "$ref" attribute don't take additional storage. |
365 return; | 365 return; |
366 } | 366 } |
367 | 367 |
368 std::string type_string; | 368 std::string type_string; |
369 base::Value::Type type = base::Value::TYPE_NULL; | 369 base::Value::Type type = base::Value::Type::NONE; |
370 if (!schema.GetString(schema::kType, &type_string) || | 370 if (!schema.GetString(schema::kType, &type_string) || |
371 !SchemaTypeToValueType(type_string, &type)) { | 371 !SchemaTypeToValueType(type_string, &type)) { |
372 // This schema is invalid. | 372 // This schema is invalid. |
373 return; | 373 return; |
374 } | 374 } |
375 | 375 |
376 sizes->schema_nodes++; | 376 sizes->schema_nodes++; |
377 | 377 |
378 if (type == base::Value::TYPE_LIST) { | 378 if (type == base::Value::Type::LIST) { |
379 const base::DictionaryValue* items = NULL; | 379 const base::DictionaryValue* items = NULL; |
380 if (schema.GetDictionary(schema::kItems, &items)) | 380 if (schema.GetDictionary(schema::kItems, &items)) |
381 DetermineStorageSizes(*items, sizes); | 381 DetermineStorageSizes(*items, sizes); |
382 } else if (type == base::Value::TYPE_DICTIONARY) { | 382 } else if (type == base::Value::Type::DICTIONARY) { |
383 sizes->properties_nodes++; | 383 sizes->properties_nodes++; |
384 | 384 |
385 const base::DictionaryValue* dict = NULL; | 385 const base::DictionaryValue* dict = NULL; |
386 if (schema.GetDictionary(schema::kAdditionalProperties, &dict)) | 386 if (schema.GetDictionary(schema::kAdditionalProperties, &dict)) |
387 DetermineStorageSizes(*dict, sizes); | 387 DetermineStorageSizes(*dict, sizes); |
388 | 388 |
389 const base::DictionaryValue* properties = NULL; | 389 const base::DictionaryValue* properties = NULL; |
390 if (schema.GetDictionary(schema::kProperties, &properties)) { | 390 if (schema.GetDictionary(schema::kProperties, &properties)) { |
391 for (base::DictionaryValue::Iterator it(*properties); | 391 for (base::DictionaryValue::Iterator it(*properties); |
392 !it.IsAtEnd(); it.Advance()) { | 392 !it.IsAtEnd(); it.Advance()) { |
(...skipping 11 matching lines...) Expand all Loading... |
404 !it.IsAtEnd(); it.Advance()) { | 404 !it.IsAtEnd(); it.Advance()) { |
405 CHECK(it.value().GetAsDictionary(&dict)); | 405 CHECK(it.value().GetAsDictionary(&dict)); |
406 DetermineStorageSizes(*dict, sizes); | 406 DetermineStorageSizes(*dict, sizes); |
407 sizes->strings++; | 407 sizes->strings++; |
408 sizes->property_nodes++; | 408 sizes->property_nodes++; |
409 } | 409 } |
410 } | 410 } |
411 } else if (schema.HasKey(schema::kEnum)) { | 411 } else if (schema.HasKey(schema::kEnum)) { |
412 const base::ListValue* possible_values = NULL; | 412 const base::ListValue* possible_values = NULL; |
413 if (schema.GetList(schema::kEnum, &possible_values)) { | 413 if (schema.GetList(schema::kEnum, &possible_values)) { |
414 if (type == base::Value::TYPE_INTEGER) { | 414 if (type == base::Value::Type::INTEGER) { |
415 sizes->int_enums += possible_values->GetSize(); | 415 sizes->int_enums += possible_values->GetSize(); |
416 } else if (type == base::Value::TYPE_STRING) { | 416 } else if (type == base::Value::Type::STRING) { |
417 sizes->string_enums += possible_values->GetSize(); | 417 sizes->string_enums += possible_values->GetSize(); |
418 sizes->strings += possible_values->GetSize(); | 418 sizes->strings += possible_values->GetSize(); |
419 } | 419 } |
420 sizes->restriction_nodes++; | 420 sizes->restriction_nodes++; |
421 } | 421 } |
422 } else if (type == base::Value::TYPE_INTEGER) { | 422 } else if (type == base::Value::Type::INTEGER) { |
423 if (schema.HasKey(schema::kMinimum) || schema.HasKey(schema::kMaximum)) | 423 if (schema.HasKey(schema::kMinimum) || schema.HasKey(schema::kMaximum)) |
424 sizes->restriction_nodes++; | 424 sizes->restriction_nodes++; |
425 } else if (type == base::Value::TYPE_STRING) { | 425 } else if (type == base::Value::Type::STRING) { |
426 if (schema.HasKey(schema::kPattern)) { | 426 if (schema.HasKey(schema::kPattern)) { |
427 sizes->strings++; | 427 sizes->strings++; |
428 sizes->string_enums++; | 428 sizes->string_enums++; |
429 sizes->restriction_nodes++; | 429 sizes->restriction_nodes++; |
430 } | 430 } |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 bool Schema::InternalStorage::Parse(const base::DictionaryValue& schema, | 434 bool Schema::InternalStorage::Parse(const base::DictionaryValue& schema, |
435 int* index, | 435 int* index, |
(...skipping 10 matching lines...) Expand all Loading... |
446 reference_list->push_back(std::make_pair(ref_string, index)); | 446 reference_list->push_back(std::make_pair(ref_string, index)); |
447 return true; | 447 return true; |
448 } | 448 } |
449 | 449 |
450 std::string type_string; | 450 std::string type_string; |
451 if (!schema.GetString(schema::kType, &type_string)) { | 451 if (!schema.GetString(schema::kType, &type_string)) { |
452 *error = "The schema type must be declared."; | 452 *error = "The schema type must be declared."; |
453 return false; | 453 return false; |
454 } | 454 } |
455 | 455 |
456 base::Value::Type type = base::Value::TYPE_NULL; | 456 base::Value::Type type = base::Value::Type::NONE; |
457 if (!SchemaTypeToValueType(type_string, &type)) { | 457 if (!SchemaTypeToValueType(type_string, &type)) { |
458 *error = "Type not supported: " + type_string; | 458 *error = "Type not supported: " + type_string; |
459 return false; | 459 return false; |
460 } | 460 } |
461 | 461 |
462 *index = static_cast<int>(schema_nodes_.size()); | 462 *index = static_cast<int>(schema_nodes_.size()); |
463 schema_nodes_.push_back(SchemaNode()); | 463 schema_nodes_.push_back(SchemaNode()); |
464 SchemaNode* schema_node = &schema_nodes_.back(); | 464 SchemaNode* schema_node = &schema_nodes_.back(); |
465 schema_node->type = type; | 465 schema_node->type = type; |
466 schema_node->extra = kInvalid; | 466 schema_node->extra = kInvalid; |
467 | 467 |
468 if (type == base::Value::TYPE_DICTIONARY) { | 468 if (type == base::Value::Type::DICTIONARY) { |
469 if (!ParseDictionary(schema, schema_node, id_map, reference_list, error)) | 469 if (!ParseDictionary(schema, schema_node, id_map, reference_list, error)) |
470 return false; | 470 return false; |
471 } else if (type == base::Value::TYPE_LIST) { | 471 } else if (type == base::Value::Type::LIST) { |
472 if (!ParseList(schema, schema_node, id_map, reference_list, error)) | 472 if (!ParseList(schema, schema_node, id_map, reference_list, error)) |
473 return false; | 473 return false; |
474 } else if (schema.HasKey(schema::kEnum)) { | 474 } else if (schema.HasKey(schema::kEnum)) { |
475 if (!ParseEnum(schema, type, schema_node, error)) | 475 if (!ParseEnum(schema, type, schema_node, error)) |
476 return false; | 476 return false; |
477 } else if (schema.HasKey(schema::kPattern)) { | 477 } else if (schema.HasKey(schema::kPattern)) { |
478 if (!ParseStringPattern(schema, schema_node, error)) | 478 if (!ParseStringPattern(schema, schema_node, error)) |
479 return false; | 479 return false; |
480 } else if (schema.HasKey(schema::kMinimum) || | 480 } else if (schema.HasKey(schema::kMinimum) || |
481 schema.HasKey(schema::kMaximum)) { | 481 schema.HasKey(schema::kMaximum)) { |
482 if (type != base::Value::TYPE_INTEGER) { | 482 if (type != base::Value::Type::INTEGER) { |
483 *error = "Only integers can have minimum and maximum"; | 483 *error = "Only integers can have minimum and maximum"; |
484 return false; | 484 return false; |
485 } | 485 } |
486 if (!ParseRangedInt(schema, schema_node, error)) | 486 if (!ParseRangedInt(schema, schema_node, error)) |
487 return false; | 487 return false; |
488 } | 488 } |
489 std::string id_string; | 489 std::string id_string; |
490 if (schema.GetString(schema::kId, &id_string)) { | 490 if (schema.GetString(schema::kId, &id_string)) { |
491 if (base::ContainsKey(*id_map, id_string)) { | 491 if (base::ContainsKey(*id_map, id_string)) { |
492 *error = "Duplicated id: " + id_string; | 492 *error = "Duplicated id: " + id_string; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (!schema.GetList(schema::kEnum, &possible_values)) { | 607 if (!schema.GetList(schema::kEnum, &possible_values)) { |
608 *error = "Enum attribute must be a list value"; | 608 *error = "Enum attribute must be a list value"; |
609 return false; | 609 return false; |
610 } | 610 } |
611 if (possible_values->empty()) { | 611 if (possible_values->empty()) { |
612 *error = "Enum attribute must be non-empty"; | 612 *error = "Enum attribute must be non-empty"; |
613 return false; | 613 return false; |
614 } | 614 } |
615 int offset_begin; | 615 int offset_begin; |
616 int offset_end; | 616 int offset_end; |
617 if (type == base::Value::TYPE_INTEGER) { | 617 if (type == base::Value::Type::INTEGER) { |
618 offset_begin = static_cast<int>(int_enums_.size()); | 618 offset_begin = static_cast<int>(int_enums_.size()); |
619 int value; | 619 int value; |
620 for (base::ListValue::const_iterator it = possible_values->begin(); | 620 for (base::ListValue::const_iterator it = possible_values->begin(); |
621 it != possible_values->end(); ++it) { | 621 it != possible_values->end(); ++it) { |
622 if (!(*it)->GetAsInteger(&value)) { | 622 if (!(*it)->GetAsInteger(&value)) { |
623 *error = "Invalid enumeration member type"; | 623 *error = "Invalid enumeration member type"; |
624 return false; | 624 return false; |
625 } | 625 } |
626 int_enums_.push_back(value); | 626 int_enums_.push_back(value); |
627 } | 627 } |
628 offset_end = static_cast<int>(int_enums_.size()); | 628 offset_end = static_cast<int>(int_enums_.size()); |
629 } else if (type == base::Value::TYPE_STRING) { | 629 } else if (type == base::Value::Type::STRING) { |
630 offset_begin = static_cast<int>(string_enums_.size()); | 630 offset_begin = static_cast<int>(string_enums_.size()); |
631 std::string value; | 631 std::string value; |
632 for (base::ListValue::const_iterator it = possible_values->begin(); | 632 for (base::ListValue::const_iterator it = possible_values->begin(); |
633 it != possible_values->end(); ++it) { | 633 it != possible_values->end(); ++it) { |
634 if (!(*it)->GetAsString(&value)) { | 634 if (!(*it)->GetAsString(&value)) { |
635 *error = "Invalid enumeration member type"; | 635 *error = "Invalid enumeration member type"; |
636 return false; | 636 return false; |
637 } | 637 } |
638 strings_.push_back(value); | 638 strings_.push_back(value); |
639 string_enums_.push_back(strings_.back().c_str()); | 639 string_enums_.push_back(strings_.back().c_str()); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 std::string* error_path, | 778 std::string* error_path, |
779 std::string* error) const { | 779 std::string* error) const { |
780 if (!valid()) { | 780 if (!valid()) { |
781 SchemaErrorFound(error_path, error, "The schema is invalid."); | 781 SchemaErrorFound(error_path, error, "The schema is invalid."); |
782 return false; | 782 return false; |
783 } | 783 } |
784 | 784 |
785 if (!value.IsType(type())) { | 785 if (!value.IsType(type())) { |
786 // Allow the integer to double promotion. Note that range restriction on | 786 // Allow the integer to double promotion. Note that range restriction on |
787 // double is not supported now. | 787 // double is not supported now. |
788 if (value.IsType(base::Value::TYPE_INTEGER) && | 788 if (value.IsType(base::Value::Type::INTEGER) && |
789 type() == base::Value::TYPE_DOUBLE) { | 789 type() == base::Value::Type::DOUBLE) { |
790 return true; | 790 return true; |
791 } | 791 } |
792 | 792 |
793 SchemaErrorFound( | 793 SchemaErrorFound( |
794 error_path, error, "The value type doesn't match the schema type."); | 794 error_path, error, "The value type doesn't match the schema type."); |
795 return false; | 795 return false; |
796 } | 796 } |
797 | 797 |
798 const base::DictionaryValue* dict = NULL; | 798 const base::DictionaryValue* dict = NULL; |
799 const base::ListValue* list = NULL; | 799 const base::ListValue* list = NULL; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 std::string* error, | 860 std::string* error, |
861 bool* changed) const { | 861 bool* changed) const { |
862 if (!valid()) { | 862 if (!valid()) { |
863 SchemaErrorFound(error_path, error, "The schema is invalid."); | 863 SchemaErrorFound(error_path, error, "The schema is invalid."); |
864 return false; | 864 return false; |
865 } | 865 } |
866 | 866 |
867 if (!value->IsType(type())) { | 867 if (!value->IsType(type())) { |
868 // Allow the integer to double promotion. Note that range restriction on | 868 // Allow the integer to double promotion. Note that range restriction on |
869 // double is not supported now. | 869 // double is not supported now. |
870 if (value->IsType(base::Value::TYPE_INTEGER) && | 870 if (value->IsType(base::Value::Type::INTEGER) && |
871 type() == base::Value::TYPE_DOUBLE) { | 871 type() == base::Value::Type::DOUBLE) { |
872 return true; | 872 return true; |
873 } | 873 } |
874 | 874 |
875 SchemaErrorFound( | 875 SchemaErrorFound( |
876 error_path, error, "The value type doesn't match the schema type."); | 876 error_path, error, "The value type doesn't match the schema type."); |
877 return false; | 877 return false; |
878 } | 878 } |
879 | 879 |
880 base::DictionaryValue* dict = NULL; | 880 base::DictionaryValue* dict = NULL; |
881 base::ListValue* list = NULL; | 881 base::ListValue* list = NULL; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 return Schema(storage, storage->root_node()); | 986 return Schema(storage, storage->root_node()); |
987 } | 987 } |
988 | 988 |
989 base::Value::Type Schema::type() const { | 989 base::Value::Type Schema::type() const { |
990 CHECK(valid()); | 990 CHECK(valid()); |
991 return node_->type; | 991 return node_->type; |
992 } | 992 } |
993 | 993 |
994 Schema::Iterator Schema::GetPropertiesIterator() const { | 994 Schema::Iterator Schema::GetPropertiesIterator() const { |
995 CHECK(valid()); | 995 CHECK(valid()); |
996 CHECK_EQ(base::Value::TYPE_DICTIONARY, type()); | 996 CHECK_EQ(base::Value::Type::DICTIONARY, type()); |
997 return Iterator(storage_, storage_->properties(node_->extra)); | 997 return Iterator(storage_, storage_->properties(node_->extra)); |
998 } | 998 } |
999 | 999 |
1000 namespace { | 1000 namespace { |
1001 | 1001 |
1002 bool CompareKeys(const PropertyNode& node, const std::string& key) { | 1002 bool CompareKeys(const PropertyNode& node, const std::string& key) { |
1003 return node.key < key; | 1003 return node.key < key; |
1004 } | 1004 } |
1005 | 1005 |
1006 } // namespace | 1006 } // namespace |
1007 | 1007 |
1008 Schema Schema::GetKnownProperty(const std::string& key) const { | 1008 Schema Schema::GetKnownProperty(const std::string& key) const { |
1009 CHECK(valid()); | 1009 CHECK(valid()); |
1010 CHECK_EQ(base::Value::TYPE_DICTIONARY, type()); | 1010 CHECK_EQ(base::Value::Type::DICTIONARY, type()); |
1011 const PropertiesNode* node = storage_->properties(node_->extra); | 1011 const PropertiesNode* node = storage_->properties(node_->extra); |
1012 const PropertyNode* begin = storage_->property(node->begin); | 1012 const PropertyNode* begin = storage_->property(node->begin); |
1013 const PropertyNode* end = storage_->property(node->end); | 1013 const PropertyNode* end = storage_->property(node->end); |
1014 const PropertyNode* it = std::lower_bound(begin, end, key, CompareKeys); | 1014 const PropertyNode* it = std::lower_bound(begin, end, key, CompareKeys); |
1015 if (it != end && it->key == key) | 1015 if (it != end && it->key == key) |
1016 return Schema(storage_, storage_->schema(it->schema)); | 1016 return Schema(storage_, storage_->schema(it->schema)); |
1017 return Schema(); | 1017 return Schema(); |
1018 } | 1018 } |
1019 | 1019 |
1020 Schema Schema::GetAdditionalProperties() const { | 1020 Schema Schema::GetAdditionalProperties() const { |
1021 CHECK(valid()); | 1021 CHECK(valid()); |
1022 CHECK_EQ(base::Value::TYPE_DICTIONARY, type()); | 1022 CHECK_EQ(base::Value::Type::DICTIONARY, type()); |
1023 const PropertiesNode* node = storage_->properties(node_->extra); | 1023 const PropertiesNode* node = storage_->properties(node_->extra); |
1024 if (node->additional == kInvalid) | 1024 if (node->additional == kInvalid) |
1025 return Schema(); | 1025 return Schema(); |
1026 return Schema(storage_, storage_->schema(node->additional)); | 1026 return Schema(storage_, storage_->schema(node->additional)); |
1027 } | 1027 } |
1028 | 1028 |
1029 SchemaList Schema::GetPatternProperties(const std::string& key) const { | 1029 SchemaList Schema::GetPatternProperties(const std::string& key) const { |
1030 CHECK(valid()); | 1030 CHECK(valid()); |
1031 CHECK_EQ(base::Value::TYPE_DICTIONARY, type()); | 1031 CHECK_EQ(base::Value::Type::DICTIONARY, type()); |
1032 const PropertiesNode* node = storage_->properties(node_->extra); | 1032 const PropertiesNode* node = storage_->properties(node_->extra); |
1033 const PropertyNode* begin = storage_->property(node->end); | 1033 const PropertyNode* begin = storage_->property(node->end); |
1034 const PropertyNode* end = storage_->property(node->pattern_end); | 1034 const PropertyNode* end = storage_->property(node->pattern_end); |
1035 SchemaList matching_properties; | 1035 SchemaList matching_properties; |
1036 for (const PropertyNode* it = begin; it != end; ++it) { | 1036 for (const PropertyNode* it = begin; it != end; ++it) { |
1037 if (re2::RE2::PartialMatch(key, *storage_->CompileRegex(it->key))) { | 1037 if (re2::RE2::PartialMatch(key, *storage_->CompileRegex(it->key))) { |
1038 matching_properties.push_back( | 1038 matching_properties.push_back( |
1039 Schema(storage_, storage_->schema(it->schema))); | 1039 Schema(storage_, storage_->schema(it->schema))); |
1040 } | 1040 } |
1041 } | 1041 } |
(...skipping 22 matching lines...) Expand all Loading... |
1064 Schema additional_property = GetAdditionalProperties(); | 1064 Schema additional_property = GetAdditionalProperties(); |
1065 if (additional_property.valid()) | 1065 if (additional_property.valid()) |
1066 schema_list.push_back(additional_property); | 1066 schema_list.push_back(additional_property); |
1067 } | 1067 } |
1068 | 1068 |
1069 return schema_list; | 1069 return schema_list; |
1070 } | 1070 } |
1071 | 1071 |
1072 Schema Schema::GetItems() const { | 1072 Schema Schema::GetItems() const { |
1073 CHECK(valid()); | 1073 CHECK(valid()); |
1074 CHECK_EQ(base::Value::TYPE_LIST, type()); | 1074 CHECK_EQ(base::Value::Type::LIST, type()); |
1075 if (node_->extra == kInvalid) | 1075 if (node_->extra == kInvalid) |
1076 return Schema(); | 1076 return Schema(); |
1077 return Schema(storage_, storage_->schema(node_->extra)); | 1077 return Schema(storage_, storage_->schema(node_->extra)); |
1078 } | 1078 } |
1079 | 1079 |
1080 bool Schema::ValidateIntegerRestriction(int index, int value) const { | 1080 bool Schema::ValidateIntegerRestriction(int index, int value) const { |
1081 const RestrictionNode* rnode = storage_->restriction(index); | 1081 const RestrictionNode* rnode = storage_->restriction(index); |
1082 if (rnode->ranged_restriction.min_value <= | 1082 if (rnode->ranged_restriction.min_value <= |
1083 rnode->ranged_restriction.max_value) { | 1083 rnode->ranged_restriction.max_value) { |
1084 return rnode->ranged_restriction.min_value <= value && | 1084 return rnode->ranged_restriction.min_value <= value && |
(...skipping 20 matching lines...) Expand all Loading... |
1105 return false; | 1105 return false; |
1106 } else { | 1106 } else { |
1107 int index = rnode->string_pattern_restriction.pattern_index; | 1107 int index = rnode->string_pattern_restriction.pattern_index; |
1108 DCHECK(index == rnode->string_pattern_restriction.pattern_index_backup); | 1108 DCHECK(index == rnode->string_pattern_restriction.pattern_index_backup); |
1109 re2::RE2* regex = storage_->CompileRegex(*storage_->string_enums(index)); | 1109 re2::RE2* regex = storage_->CompileRegex(*storage_->string_enums(index)); |
1110 return re2::RE2::PartialMatch(str, *regex); | 1110 return re2::RE2::PartialMatch(str, *regex); |
1111 } | 1111 } |
1112 } | 1112 } |
1113 | 1113 |
1114 } // namespace policy | 1114 } // namespace policy |
OLD | NEW |