-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
#include "PropertyUtil.h" | ||
#include "Ice/StringUtil.h" | ||
|
||
using namespace std; | ||
|
||
optional<IceInternal::Property> | ||
IceInternal::findInPropertyArray(const PropertyArray* propertyArray, string_view key) | ||
{ | ||
for (int i = 0; i < propertyArray->length; ++i) | ||
{ | ||
auto prop = propertyArray->properties[i]; | ||
|
||
// If the key is an exact match, return the property if it's not a property class. If it is, return nullopt. | ||
// If the key is a regex match, return the property. A property cannot have a property class and use regex. | ||
if (key == prop.pattern) | ||
{ | ||
if (prop.propertyClass != nullptr && prop.prefixOnly) | ||
{ | ||
return nullopt; | ||
} | ||
return prop; | ||
} | ||
else if (prop.usesRegex && IceInternal::match(string{key}, prop.pattern)) | ||
{ | ||
return prop; | ||
} | ||
|
||
// If the property has a property class, check if the key is a prefix of the property. | ||
if (prop.propertyClass) | ||
{ | ||
auto pattern = string{prop.pattern}; | ||
// Check if the key is a prefix of the property. | ||
// The key must be: | ||
// - shorter than the property pattern | ||
// - the property pattern must start with the key | ||
// - the pattern character after the key must be a dot | ||
if (key.length() > pattern.length() && key.find(pattern) == 0 && key[pattern.length()] == '.') | ||
{ | ||
// Plus one to skip the dot. | ||
string_view substring = key.substr(pattern.length() + 1); | ||
// Check if the suffix is a valid property. If so, return it. If it's not, continue searching | ||
// the current property array. | ||
if (auto subProp = findInPropertyArray(prop.propertyClass, substring)) | ||
{ | ||
return subProp; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nullopt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
#ifndef ICE_PROPERTY_UTIL_H | ||
#define ICE_PROPERTY_UTIL_H | ||
|
||
#include "PropertyNames.h" | ||
|
||
namespace IceInternal | ||
{ | ||
/// Searches a property array for a property with the given key. | ||
/// @param propertyArray The property array to search. | ||
/// @param key The key to search for. | ||
/// @return The property if found, nullopt otherwise. | ||
std::optional<Property> findInPropertyArray(const PropertyArray* propertyArray, std::string_view key); | ||
} | ||
|
||
#endif |