Skip to content

Commit

Permalink
TextView: Fix OSX issue with u_char.
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidWallOfCode committed Nov 27, 2023
1 parent 1c7af86 commit 2734914
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions code/include/swoc/TextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,30 @@ class CharSet {
using self_type = CharSet;

public:
/** Construct from character sequence.
*
* @param chars Character sequence.
*
* The charset becomes @c true for every character in the sequence.
*/
constexpr CharSet(TextView const &chars);
bool
operator()(u_char idx) const {
return _chars[idx];
}

/** Check if character is in the charset.
*
* @param c Character to check.
* @return @c true if @a c is in the charset, @c false if not.
*/
bool operator()(unsigned char c) const;

/** Check if character is in the charset.
*
* @param c Character to check.
* @return @c true if @a c is in the charset, @c false if not.
*/
bool operator()(char c) const;

protected:
std::bitset<256> _chars;
std::bitset<std::numeric_limits<unsigned char>::max() + 1> _chars;
};

/** A read only view of a contiguous piece of memory.
Expand Down Expand Up @@ -1088,10 +1104,18 @@ double svtod(TextView text, TextView *parsed = nullptr);

inline constexpr CharSet::CharSet(TextView const &chars) {
for (auto c : chars) {
_chars[u_char(c)] = true;
_chars[uint8_t(c)] = true;
}
}

inline bool CharSet::operator()(unsigned char c) const {
return _chars[c];
}

inline bool CharSet::operator()(char c) const {
return _chars[uint8_t(c)];
}

// === TextView Implementation ===
/// @cond TextView_INTERNAL
// Doxygen doesn't match these up well due to various type and template issues.
Expand Down

0 comments on commit 2734914

Please sign in to comment.