MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / is_whitespace

Function is_whitespace

src/runtime.cpp:76–95  ·  view source on GitHub ↗

std::isspace has a few edge cases that would trigger UB. In particular, the documentation says: "The behavior is undefined if the value of the input is not representable as unsigned char and is not equal to EOF." So, this function does the simple obvious thing instead.

Source from the content-addressed store, hash-verified

74// "The behavior is undefined if the value of the input is not representable as unsigned char and is not equal to EOF."
75// So, this function does the simple obvious thing instead.
76static inline bool is_whitespace(int ch)
77{
78 constexpr int space = 0x20; // space (0x20, ' ')
79 constexpr int form_feed = 0x0c; // form feed (0x0c, '\f')
80 constexpr int line_feed = 0x0a; // line feed (0x0a, '\n')
81 constexpr int carriage_return = 0x0d; // carriage return (0x0d, '\r')
82 constexpr int horizontal_tab = 0x09; // horizontal tab (0x09, '\t')
83 constexpr int vertical_tab = 0x0b; // vertical tab (0x0b, '\v')
84 switch (ch) {
85 case space:
86 case form_feed:
87 case line_feed:
88 case carriage_return:
89 case horizontal_tab:
90 case vertical_tab:
91 return true;
92 default:
93 return false;
94 }
95}
96
97static inline std::string trim(std::string s)
98{

Callers 1

trimFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected