mirror of
https://github.com/tristanpenman/valijson.git
synced 2025-03-03 12:58:03 +01:00
Minor tweaks for consistency with coding style
This commit is contained in:
parent
3d3f76df10
commit
29721d5538
2
Authors
2
Authors
@ -20,4 +20,4 @@ Richard Clamp, richardc@unixbeard.net
|
||||
Boost-related fixes
|
||||
|
||||
Lars Immisch, lars@ibp.de
|
||||
noboost branch
|
||||
noboost branch
|
||||
|
@ -210,7 +210,7 @@ int main(int argc, char *argv[])
|
||||
while (results.popError(error)) {
|
||||
cerr << "Error #" << errorNum << std::endl;
|
||||
cerr << " ";
|
||||
for( const std::string contextElement : error.context ) {
|
||||
for (const std::string &contextElement : error.context) {
|
||||
cerr << contextElement << " ";
|
||||
}
|
||||
cerr << endl;
|
||||
|
@ -25,15 +25,25 @@ namespace adapters {
|
||||
* See http://www.stlsoft.org/doc-1.9/group__group____pattern____dereference__proxy.html
|
||||
* for motivation
|
||||
*
|
||||
* @tparam Value Name of the value type
|
||||
* @tparam Value Name of the value type
|
||||
*/
|
||||
template<class Value>
|
||||
struct DerefProxy
|
||||
{
|
||||
explicit DerefProxy(const Value& x) : m_ref(x) {}
|
||||
Value* operator->() { return std::addressof(m_ref); }
|
||||
operator Value*() { return std::addressof(m_ref); }
|
||||
explicit DerefProxy(const Value& x)
|
||||
: m_ref(x) { }
|
||||
|
||||
Value* operator->()
|
||||
{
|
||||
return std::addressof(m_ref);
|
||||
}
|
||||
|
||||
operator Value*()
|
||||
{
|
||||
return std::addressof(m_ref);
|
||||
}
|
||||
|
||||
private:
|
||||
Value m_ref;
|
||||
};
|
||||
|
||||
@ -239,7 +249,7 @@ public:
|
||||
// definitely an array.
|
||||
if (value.isArray()) {
|
||||
const opt::optional<Array> array = value.getArrayOptional();
|
||||
for( const AdapterType element : *array ) {
|
||||
for (const AdapterType element : *array) {
|
||||
if (!fn(element)) {
|
||||
return false;
|
||||
}
|
||||
@ -257,7 +267,7 @@ public:
|
||||
|
||||
if (value.isObject()) {
|
||||
const opt::optional<Object> object = value.getObjectOptional();
|
||||
for( const ObjectMemberType member : *object ) {
|
||||
for (const ObjectMemberType member : *object) {
|
||||
if (!fn(member.first, AdapterType(member.second))) {
|
||||
return false;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
void applyToSubschemas(const FunctorType &fn) const
|
||||
{
|
||||
unsigned int index = 0;
|
||||
for( const Subschema *subschema : subschemas ) {
|
||||
for (const Subschema *subschema : subschemas) {
|
||||
if (!fn(index, subschema)) {
|
||||
return;
|
||||
}
|
||||
@ -100,7 +100,7 @@ public:
|
||||
void applyToSubschemas(const FunctorType &fn) const
|
||||
{
|
||||
unsigned int index = 0;
|
||||
for( const Subschema *subschema : subschemas ) {
|
||||
for (const Subschema *subschema : subschemas) {
|
||||
if (!fn(index, subschema)) {
|
||||
return;
|
||||
}
|
||||
@ -167,7 +167,7 @@ public:
|
||||
}
|
||||
|
||||
typedef typename ContainerType::value_type ValueType;
|
||||
for( const ValueType &dependencyName : dependencyNames ) {
|
||||
for (const ValueType &dependencyName : dependencyNames) {
|
||||
itr->second.insert(String(dependencyName.c_str(), allocator));
|
||||
}
|
||||
|
||||
@ -193,8 +193,7 @@ public:
|
||||
template<typename FunctorType>
|
||||
void applyToPropertyDependencies(const FunctorType &fn) const
|
||||
{
|
||||
for( const PropertyDependencies::value_type &v :
|
||||
propertyDependencies ) {
|
||||
for (const PropertyDependencies::value_type &v : propertyDependencies) {
|
||||
if (!fn(v.first, v.second)) {
|
||||
return;
|
||||
}
|
||||
@ -204,8 +203,7 @@ public:
|
||||
template<typename FunctorType>
|
||||
void applyToSchemaDependencies(const FunctorType &fn) const
|
||||
{
|
||||
for( const SchemaDependencies::value_type &v :
|
||||
schemaDependencies ) {
|
||||
for (const SchemaDependencies::value_type &v : schemaDependencies) {
|
||||
if (!fn(v.first, v.second)) {
|
||||
return;
|
||||
}
|
||||
@ -251,7 +249,7 @@ public:
|
||||
{
|
||||
try {
|
||||
// Clone individual enum values
|
||||
for( const EnumValue *otherValue : other.enumValues ) {
|
||||
for (const EnumValue *otherValue : other.enumValues) {
|
||||
const EnumValue *value = otherValue->clone();
|
||||
try {
|
||||
enumValues.push_back(value);
|
||||
@ -263,7 +261,7 @@ public:
|
||||
|
||||
} catch (...) {
|
||||
// Delete values already added to constraint
|
||||
for( const EnumValue *value : enumValues ) {
|
||||
for (const EnumValue *value : enumValues) {
|
||||
delete value;
|
||||
}
|
||||
throw;
|
||||
@ -272,7 +270,7 @@ public:
|
||||
|
||||
virtual ~EnumConstraint()
|
||||
{
|
||||
for( const EnumValue *value : enumValues ) {
|
||||
for (const EnumValue *value : enumValues) {
|
||||
delete value;
|
||||
}
|
||||
}
|
||||
@ -292,7 +290,7 @@ public:
|
||||
template<typename FunctorType>
|
||||
void applyToValues(const FunctorType &fn) const
|
||||
{
|
||||
for( const EnumValue *value : enumValues ) {
|
||||
for (const EnumValue *value : enumValues) {
|
||||
if (!fn(*value)) {
|
||||
return;
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ namespace json_pointer {
|
||||
* @param search string to search
|
||||
* @param replace replacement string
|
||||
*/
|
||||
|
||||
inline void replace_all_inplace(std::string& subject, const char* search,
|
||||
const char* replace)
|
||||
{
|
||||
|
@ -174,7 +174,7 @@ private:
|
||||
{
|
||||
typedef typename DocumentCache<AdapterType>::Type DocCacheType;
|
||||
|
||||
for( const typename DocCacheType::value_type &v : docCache ) {
|
||||
for (const typename DocCacheType::value_type &v : docCache) {
|
||||
freeDoc(v.second);
|
||||
}
|
||||
}
|
||||
@ -314,7 +314,7 @@ private:
|
||||
const std::vector<std::string> &keysToCreate,
|
||||
const Subschema *schema)
|
||||
{
|
||||
for( const std::string &keyToCreate : keysToCreate ) {
|
||||
for (const std::string &keyToCreate : keysToCreate) {
|
||||
const SchemaCache::value_type value(keyToCreate, schema);
|
||||
if (!schemaCache.insert(value).second) {
|
||||
throw std::logic_error(
|
||||
@ -1180,7 +1180,7 @@ private:
|
||||
if (member.second.maybeArray()) {
|
||||
// Parse an array of dependency names
|
||||
std::vector<std::string> dependentPropertyNames;
|
||||
for( const AdapterType dependencyName : member.second.asArray() ) {
|
||||
for (const AdapterType dependencyName : member.second.asArray()) {
|
||||
if (dependencyName.maybeString()) {
|
||||
dependentPropertyNames.push_back(dependencyName.getString());
|
||||
} else {
|
||||
@ -1237,7 +1237,7 @@ private:
|
||||
{
|
||||
// Make a copy of each value in the enum array
|
||||
constraints::EnumConstraint constraint;
|
||||
for( const AdapterType value : node.getArray() ) {
|
||||
for (const AdapterType value : node.getArray()) {
|
||||
constraint.addValue(value);
|
||||
}
|
||||
|
||||
@ -1335,7 +1335,7 @@ private:
|
||||
// validate the values at the corresponding indexes in a target
|
||||
// array.
|
||||
int index = 0;
|
||||
for( const AdapterType v : items->getArray() ) {
|
||||
for (const AdapterType v : items->getArray()) {
|
||||
const std::string childPath = itemsPath + "/" +
|
||||
std::to_string(index);
|
||||
const Subschema *subschema = makeOrReuseSchema<AdapterType>(
|
||||
@ -1861,7 +1861,7 @@ private:
|
||||
|
||||
// Create subschemas for 'properties' constraint
|
||||
if (properties) {
|
||||
for( const Member m : properties->getObject() ) {
|
||||
for (const Member m : properties->getObject()) {
|
||||
const std::string &property = m.first;
|
||||
const std::string childPath = propertiesPath + "/" + property;
|
||||
const Subschema *subschema = makeOrReuseSchema<AdapterType>(
|
||||
@ -1874,7 +1874,7 @@ private:
|
||||
|
||||
// Create subschemas for 'patternProperties' constraint
|
||||
if (patternProperties) {
|
||||
for( const Member m : patternProperties->getObject() ) {
|
||||
for (const Member m : patternProperties->getObject()) {
|
||||
const std::string &pattern = m.first;
|
||||
const std::string childPath = patternPropertiesPath + "/" +
|
||||
pattern;
|
||||
@ -1973,7 +1973,7 @@ private:
|
||||
{
|
||||
constraints::RequiredConstraint constraint;
|
||||
|
||||
for( const AdapterType v : node.getArray() ) {
|
||||
for (const AdapterType v : node.getArray()) {
|
||||
if (!v.isString()) {
|
||||
throw std::runtime_error("Expected required property name to "
|
||||
"be a string value");
|
||||
@ -2030,7 +2030,7 @@ private:
|
||||
|
||||
} else if (node.isArray()) {
|
||||
int index = 0;
|
||||
for( const AdapterType v : node.getArray() ) {
|
||||
for (const AdapterType v : node.getArray()) {
|
||||
if (v.isString()) {
|
||||
const TypeConstraint::JsonType type =
|
||||
TypeConstraint::jsonTypeFromString(v.getString());
|
||||
|
@ -121,7 +121,7 @@ public:
|
||||
bool apply(ApplyFunction &applyFunction) const
|
||||
{
|
||||
bool allTrue = true;
|
||||
for( const Constraint *constraint : constraints ) {
|
||||
for (const Constraint *constraint : constraints) {
|
||||
allTrue = allTrue && applyFunction(*constraint);
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ public:
|
||||
*/
|
||||
bool applyStrict(ApplyFunction &applyFunction) const
|
||||
{
|
||||
for( const Constraint *constraint : constraints ) {
|
||||
for (const Constraint *constraint : constraints) {
|
||||
if (!applyFunction(*constraint)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -875,7 +875,7 @@ public:
|
||||
return validated;
|
||||
}
|
||||
|
||||
for( const typename AdapterType::ObjectMember m : object ) {
|
||||
for (const typename AdapterType::ObjectMember m : object) {
|
||||
if (propertiesMatched.find(m.first) == propertiesMatched.end()) {
|
||||
// Update context
|
||||
std::vector<std::string> newContext = context;
|
||||
@ -956,7 +956,7 @@ public:
|
||||
bool validated = true;
|
||||
|
||||
unsigned int index = 0;
|
||||
for( const AdapterType &item : target.getArray() ) {
|
||||
for (const AdapterType &item : target.getArray()) {
|
||||
// Update context for current array item
|
||||
std::vector<std::string> newContext = context;
|
||||
newContext.push_back("[" +
|
||||
@ -1199,7 +1199,7 @@ private:
|
||||
}
|
||||
|
||||
typedef typename ContainerType::value_type ValueType;
|
||||
for( const ValueType &dependencyName : dependencyNames ) {
|
||||
for (const ValueType &dependencyName : dependencyNames) {
|
||||
const std::string dependencyNameKey(dependencyName.c_str());
|
||||
if (object.find(dependencyNameKey) == object.end()) {
|
||||
if (validated) {
|
||||
@ -1411,7 +1411,7 @@ private:
|
||||
|
||||
// Recursively validate all matching properties
|
||||
typedef const typename AdapterType::ObjectMember ObjectMember;
|
||||
for( const ObjectMember m : object ) {
|
||||
for (const ObjectMember m : object) {
|
||||
if (std::regex_search(m.first, r)) {
|
||||
matchFound = true;
|
||||
if (propertiesMatched) {
|
||||
|
@ -35,7 +35,7 @@ TEST_F(TestJson11Adapter, BasicArrayIteration)
|
||||
|
||||
// Ensure that the elements are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::Json11Adapter value : adapter.getArray() ) {
|
||||
for (const valijson::adapters::Json11Adapter value : adapter.getArray()) {
|
||||
ASSERT_TRUE( value.isNumber() );
|
||||
EXPECT_EQ( double(expectedValue), value.getDouble() );
|
||||
expectedValue++;
|
||||
@ -72,7 +72,7 @@ TEST_F(TestJson11Adapter, BasicObjectIteration)
|
||||
|
||||
// Ensure that the members are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::Json11Adapter::ObjectMember member : adapter.getObject() ) {
|
||||
for (const valijson::adapters::Json11Adapter::ObjectMember member : adapter.getObject()) {
|
||||
ASSERT_TRUE( member.second.isNumber() );
|
||||
EXPECT_EQ( std::to_string(expectedValue), member.first );
|
||||
EXPECT_EQ( double(expectedValue), member.second.getDouble() );
|
||||
|
@ -32,7 +32,7 @@ TEST_F(TestJsonCppAdapter, BasicArrayIteration)
|
||||
|
||||
// Ensure that the elements are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::JsonCppAdapter value : adapter.getArray() ) {
|
||||
for (const valijson::adapters::JsonCppAdapter value : adapter.getArray()) {
|
||||
ASSERT_TRUE( value.isNumber() );
|
||||
EXPECT_EQ( double(expectedValue), value.getNumber() );
|
||||
expectedValue++;
|
||||
@ -68,7 +68,7 @@ TEST_F(TestJsonCppAdapter, BasicObjectIteration)
|
||||
|
||||
// Ensure that the members are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::JsonCppAdapter::ObjectMember member : adapter.getObject() ) {
|
||||
for (const valijson::adapters::JsonCppAdapter::ObjectMember member : adapter.getObject()) {
|
||||
ASSERT_TRUE( member.second.isNumber() );
|
||||
EXPECT_EQ( std::to_string(expectedValue), member.first );
|
||||
EXPECT_EQ( double(expectedValue), member.second.getDouble() );
|
||||
|
@ -34,7 +34,7 @@ TEST_F(TestNlohmannJsonAdapter, BasicArrayIteration)
|
||||
|
||||
// Ensure that the elements are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::NlohmannJsonAdapter value : adapter.getArray() ) {
|
||||
for (const valijson::adapters::NlohmannJsonAdapter value : adapter.getArray()) {
|
||||
ASSERT_TRUE( value.isNumber() );
|
||||
EXPECT_EQ( double(expectedValue), value.getDouble() );
|
||||
expectedValue++;
|
||||
@ -69,7 +69,7 @@ TEST_F(TestNlohmannJsonAdapter, BasicObjectIteration)
|
||||
|
||||
// Ensure that the members are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::NlohmannJsonAdapter::ObjectMember member : adapter.getObject() ) {
|
||||
for (const valijson::adapters::NlohmannJsonAdapter::ObjectMember member : adapter.getObject()) {
|
||||
ASSERT_TRUE( member.second.isNumber() );
|
||||
EXPECT_EQ( std::to_string(expectedValue), member.first );
|
||||
EXPECT_EQ( double(expectedValue), member.second.getDouble() );
|
||||
|
@ -35,7 +35,7 @@ TEST_F(TestPicoJsonAdapter, BasicArrayIteration)
|
||||
|
||||
// Ensure that the elements are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::PicoJsonAdapter value : adapter.getArray() ) {
|
||||
for (const valijson::adapters::PicoJsonAdapter value : adapter.getArray()) {
|
||||
ASSERT_TRUE( value.isNumber() );
|
||||
EXPECT_EQ( double(expectedValue), value.getDouble() );
|
||||
expectedValue++;
|
||||
@ -72,7 +72,7 @@ TEST_F(TestPicoJsonAdapter, BasicObjectIteration)
|
||||
|
||||
// Ensure that the members are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::PicoJsonAdapter::ObjectMember member : adapter.getObject() ) {
|
||||
for (const valijson::adapters::PicoJsonAdapter::ObjectMember member : adapter.getObject()) {
|
||||
ASSERT_TRUE( member.second.isNumber() );
|
||||
EXPECT_EQ( std::to_string(expectedValue), member.first );
|
||||
EXPECT_EQ( double(expectedValue), member.second.getDouble() );
|
||||
|
@ -34,7 +34,7 @@ TEST_F(TestPropertyTreeAdapter, BasicArrayIteration)
|
||||
|
||||
// Ensure that the elements are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::PropertyTreeAdapter value : adapter.getArray() ) {
|
||||
for (const valijson::adapters::PropertyTreeAdapter value : adapter.getArray()) {
|
||||
ASSERT_TRUE( value.isString() );
|
||||
ASSERT_FALSE( value.isNumber() );
|
||||
ASSERT_TRUE( value.maybeDouble() );
|
||||
@ -73,7 +73,7 @@ TEST_F(TestPropertyTreeAdapter, BasicObjectIteration)
|
||||
|
||||
// Ensure that the members are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::PropertyTreeAdapter::ObjectMember member : adapter.getObject() ) {
|
||||
for (const valijson::adapters::PropertyTreeAdapter::ObjectMember member : adapter.getObject()) {
|
||||
ASSERT_TRUE( member.second.isString() );
|
||||
ASSERT_FALSE( member.second.isNumber() );
|
||||
ASSERT_TRUE( member.second.maybeDouble() );
|
||||
|
@ -37,7 +37,7 @@ void testBasicArrayIteration()
|
||||
|
||||
// Ensure that the elements are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::RapidJsonAdapter value : adapter.getArray() ) {
|
||||
for (const valijson::adapters::RapidJsonAdapter value : adapter.getArray()) {
|
||||
ASSERT_TRUE( value.isNumber() );
|
||||
EXPECT_EQ( double(expectedValue), value.getDouble() );
|
||||
expectedValue++;
|
||||
@ -77,7 +77,7 @@ void testBasicObjectIteration()
|
||||
|
||||
// Ensure that the members are returned in the order they were inserted
|
||||
unsigned int expectedValue = 0;
|
||||
for( const valijson::adapters::RapidJsonAdapter::ObjectMember member : adapter.getObject() ) {
|
||||
for (const valijson::adapters::RapidJsonAdapter::ObjectMember member : adapter.getObject()) {
|
||||
ASSERT_TRUE( member.second.isNumber() );
|
||||
EXPECT_EQ( std::to_string(expectedValue), member.first );
|
||||
EXPECT_EQ( double(expectedValue), member.second.getDouble() );
|
||||
|
@ -96,7 +96,7 @@ protected:
|
||||
ASSERT_TRUE( testCases.isArray() );
|
||||
|
||||
// Process each test case in the file
|
||||
for( const AdapterType testCase : testCases.getArray() ) {
|
||||
for (const AdapterType testCase : testCases.getArray()) {
|
||||
|
||||
currentTestCase.clear();
|
||||
currentTest.clear();
|
||||
@ -124,7 +124,7 @@ protected:
|
||||
itr = object.find("tests");
|
||||
ASSERT_NE( object.end(), itr );
|
||||
ASSERT_TRUE( itr->second.isArray() );
|
||||
for( const AdapterType test : itr->second.getArray() ) {
|
||||
for (const AdapterType test : itr->second.getArray()) {
|
||||
|
||||
const bool strict = itr->second.hasStrictTypes();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user