Replace 'ref' arguments with plain pointers
This commit is contained in:
parent
ad768711ff
commit
78ce7fb77a
@ -79,8 +79,8 @@ class <%= @classname %>
|
|||||||
* - P_EOF
|
* - P_EOF
|
||||||
*/
|
*/
|
||||||
static size_t decode_code_point(string input,
|
static size_t decode_code_point(string input,
|
||||||
ref CodePoint out_code_point,
|
CodePoint * out_code_point,
|
||||||
ref ubyte out_code_point_length)
|
ubyte * out_code_point_length)
|
||||||
{
|
{
|
||||||
if (input.length == 0u)
|
if (input.length == 0u)
|
||||||
{
|
{
|
||||||
@ -141,8 +141,8 @@ class <%= @classname %>
|
|||||||
code_point = (code_point << 6u) | (b & 0x3Fu);
|
code_point = (code_point << 6u) | (b & 0x3Fu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out_code_point = code_point;
|
*out_code_point = code_point;
|
||||||
out_code_point_length = code_point_length;
|
*out_code_point_length = code_point_length;
|
||||||
return P_SUCCESS;
|
return P_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,7 +291,7 @@ class <%= @classname %>
|
|||||||
*out_token_info = token_info; // TODO: remove
|
*out_token_info = token_info; // TODO: remove
|
||||||
MatchInfo match_info;
|
MatchInfo match_info;
|
||||||
size_t unexpected_input_length;
|
size_t unexpected_input_length;
|
||||||
size_t result = find_longest_match(match_info, unexpected_input_length);
|
size_t result = find_longest_match(&match_info, &unexpected_input_length);
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case P_SUCCESS:
|
case P_SUCCESS:
|
||||||
@ -356,8 +356,8 @@ class <%= @classname %>
|
|||||||
* - P_EOF
|
* - P_EOF
|
||||||
*/
|
*/
|
||||||
private size_t find_longest_match(
|
private size_t find_longest_match(
|
||||||
ref MatchInfo out_match_info,
|
MatchInfo * out_match_info,
|
||||||
ref size_t out_unexpected_input_length)
|
size_t * out_unexpected_input_length)
|
||||||
{
|
{
|
||||||
MatchInfo longest_match;
|
MatchInfo longest_match;
|
||||||
MatchInfo attempt_match;
|
MatchInfo attempt_match;
|
||||||
@ -367,7 +367,7 @@ class <%= @classname %>
|
|||||||
string input = m_input[(m_input_index + attempt_match.length)..(m_input.length)];
|
string input = m_input[(m_input_index + attempt_match.length)..(m_input.length)];
|
||||||
CodePoint code_point;
|
CodePoint code_point;
|
||||||
ubyte code_point_length;
|
ubyte code_point_length;
|
||||||
size_t result = Decoder.decode_code_point(input, code_point, code_point_length);
|
size_t result = Decoder.decode_code_point(input, &code_point, &code_point_length);
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case P_SUCCESS:
|
case P_SUCCESS:
|
||||||
@ -393,12 +393,12 @@ class <%= @classname %>
|
|||||||
}
|
}
|
||||||
else if (longest_match.length > 0)
|
else if (longest_match.length > 0)
|
||||||
{
|
{
|
||||||
out_match_info = longest_match;
|
*out_match_info = longest_match;
|
||||||
return P_SUCCESS;
|
return P_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
out_unexpected_input_length = attempt_match.length + code_point_length;
|
*out_unexpected_input_length = attempt_match.length + code_point_length;
|
||||||
return P_UNEXPECTED_INPUT;
|
return P_UNEXPECTED_INPUT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -408,13 +408,13 @@ class <%= @classname %>
|
|||||||
if (longest_match.length > 0)
|
if (longest_match.length > 0)
|
||||||
{
|
{
|
||||||
/* We have a match, so use it. */
|
/* We have a match, so use it. */
|
||||||
out_match_info = longest_match;
|
*out_match_info = longest_match;
|
||||||
return P_SUCCESS;
|
return P_SUCCESS;
|
||||||
}
|
}
|
||||||
else if (attempt_match.length != 0)
|
else if (attempt_match.length != 0)
|
||||||
{
|
{
|
||||||
/* There is a partial match - error! */
|
/* There is a partial match - error! */
|
||||||
out_unexpected_input_length = attempt_match.length;
|
*out_unexpected_input_length = attempt_match.length;
|
||||||
return P_UNEXPECTED_INPUT;
|
return P_UNEXPECTED_INPUT;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -12,31 +12,31 @@ unittest
|
|||||||
Testparser.CodePoint code_point;
|
Testparser.CodePoint code_point;
|
||||||
ubyte code_point_length;
|
ubyte code_point_length;
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("5", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("5", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_SUCCESS);
|
assert(result == Testparser.P_SUCCESS);
|
||||||
assert(code_point == '5');
|
assert(code_point == '5');
|
||||||
assert(code_point_length == 1u);
|
assert(code_point_length == 1u);
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_EOF);
|
assert(result == Testparser.P_EOF);
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("\xC2\xA9", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("\xC2\xA9", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_SUCCESS);
|
assert(result == Testparser.P_SUCCESS);
|
||||||
assert(code_point == 0xA9u);
|
assert(code_point == 0xA9u);
|
||||||
assert(code_point_length == 2u);
|
assert(code_point_length == 2u);
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xa1", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xa1", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_SUCCESS);
|
assert(result == Testparser.P_SUCCESS);
|
||||||
assert(code_point == 0x1F9E1u);
|
assert(code_point == 0x1F9E1u);
|
||||||
assert(code_point_length == 4u);
|
assert(code_point_length == 4u);
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("\xf0\x9f\x27", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("\xf0\x9f\x27", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_DECODE_ERROR);
|
assert(result == Testparser.P_DECODE_ERROR);
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xFF", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("\xf0\x9f\xa7\xFF", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_DECODE_ERROR);
|
assert(result == Testparser.P_DECODE_ERROR);
|
||||||
|
|
||||||
result = Testparser.Decoder.decode_code_point("\xfe", code_point, code_point_length);
|
result = Testparser.Decoder.decode_code_point("\xfe", &code_point, &code_point_length);
|
||||||
assert(result == Testparser.P_DECODE_ERROR);
|
assert(result == Testparser.P_DECODE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user