-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into disable_verbose_logging_in_ci
- Loading branch information
Showing
14 changed files
with
277 additions
and
205 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
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) Microsoft Corporation. All rights reserved. | ||
// Licensed under the Apache 2.0 License. | ||
|
||
#include "ccf/ds/nonstd.h" | ||
|
||
#include "ds/nonstd.h" | ||
|
||
#include <algorithm> | ||
#include <regex> | ||
#include <string> | ||
|
||
#define FMT_HEADER_ONLY | ||
#include <fmt/format.h> | ||
|
||
namespace ccf::nonstd | ||
{ | ||
// Implementations for ccf/ds/nonstd.h | ||
void to_upper(std::string& s) | ||
{ | ||
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { | ||
return std::toupper(c); | ||
}); | ||
} | ||
|
||
void to_lower(std::string& s) | ||
{ | ||
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { | ||
return std::tolower(c); | ||
}); | ||
} | ||
|
||
// Implementations for ds/nonstd.h | ||
std::string camel_case( | ||
std::string s, bool camel_first, const std::string& separator_regex) | ||
{ | ||
// Replacement is always a 1-character string | ||
std::string replacement(1, '\0'); | ||
|
||
std::string prefix_matcher = | ||
camel_first ? fmt::format("(^|{})", separator_regex) : separator_regex; | ||
std::regex re(prefix_matcher + "[a-z]"); | ||
std::smatch match; | ||
|
||
while (std::regex_search(s, match, re)) | ||
{ | ||
// Replacement is the upper-casing of the final character from the match | ||
replacement[0] = std::toupper(match.str()[match.length() - 1]); | ||
|
||
s = s.replace(match.position(), match.length(), replacement); | ||
} | ||
|
||
return s; | ||
} | ||
} |
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,61 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the Apache 2.0 License. | ||
#pragma once | ||
#include <string> | ||
|
||
namespace ccf::nonstd | ||
{ | ||
// Iterators for map-keys and map-values | ||
template <typename TMapIterator> | ||
class KeyIterator : public TMapIterator | ||
{ | ||
public: | ||
KeyIterator() : TMapIterator() {} | ||
KeyIterator(TMapIterator it) : TMapIterator(it) {} | ||
|
||
using Key = | ||
typename std::iterator_traits<TMapIterator>::value_type::first_type; | ||
using value_type = Key; | ||
|
||
Key* operator->() | ||
{ | ||
return TMapIterator::operator->()->first; | ||
} | ||
|
||
Key operator*() | ||
{ | ||
return TMapIterator::operator*().first; | ||
} | ||
}; | ||
|
||
template <typename TMapIterator> | ||
class ValueIterator : public TMapIterator | ||
{ | ||
public: | ||
ValueIterator() : TMapIterator() {} | ||
ValueIterator(TMapIterator it) : TMapIterator(it) {} | ||
|
||
using Value = | ||
typename std::iterator_traits<TMapIterator>::value_type::second_type; | ||
using value_type = Value; | ||
|
||
Value* operator->() | ||
{ | ||
return TMapIterator::operator->()->second; | ||
} | ||
|
||
Value operator*() | ||
{ | ||
return TMapIterator::operator*().second; | ||
} | ||
}; | ||
|
||
std::string camel_case( | ||
std::string s, | ||
// Should the first character be upper-cased? | ||
bool camel_first = true, | ||
// Regex fragment to identify which characters should be upper-cased, by | ||
// matching a separator preceding them. Default is to match any | ||
// non-alphanumeric character | ||
const std::string& separator_regex = "[^[:alnum:]]"); | ||
} |
Oops, something went wrong.