Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted Java array-style ref/out/return values into ref/out parameters in .NET (Fixes #57) #61

Merged
merged 19 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ed5da25
BREAKING: ICU4N.Impl.Utility::ParseInteger(): Converted pos parameter…
NightOwl888 Nov 17, 2023
acdf02f
BREAKING: ICU4N.Impl.Utility::ParseUnicodeIdentifier(): Converted pos…
NightOwl888 Nov 17, 2023
b8e2d2d
BREAKING: ICU4N.Impl.Utility::ParseNumber(): Changed pos parameter fr…
NightOwl888 Nov 17, 2023
8f1d1e2
BREAKING: ICU4N.Impl.Utility (EncodeRun + AppendEncodedByte): Convert…
NightOwl888 Nov 17, 2023
f9b2780
BREAKING: ICU4N.Impl.Utility::ParseChar(): Converted pos parameter fr…
NightOwl888 Nov 17, 2023
46229ce
ICU4N.Transliterator.Text.TransliteratorIDParser (ParseFilterID() + P…
NightOwl888 Nov 17, 2023
a1fe698
ICU4N.Transliterator.Text.TransliteratorIDParser::ParseGlobalFilter()…
NightOwl888 Nov 17, 2023
41ceea3
ICU4N.Transliterator.Text.TransliteratorIDParser::ParseCompoundID(): …
NightOwl888 Nov 17, 2023
0a1cdf1
BREAKING: ICU4N.Text.IUnicodeMatcher::Matches(): Changed offset param…
NightOwl888 Nov 17, 2023
4a37d18
BREAKING: ICU4N.Text.IUnicodeReplacer::Replace(): Changed cursor para…
NightOwl888 Nov 17, 2023
c527f4b
BREAKING: ICU4N.Impl.ICUResourceBundle::GetFunctionalEquivalent() + I…
NightOwl888 Nov 17, 2023
966f0c7
BREAKING: ICU4N.Impl.Int32TrieBuilder::GetValue(): Changed inBlockZer…
NightOwl888 Nov 17, 2023
5a7192d
ICU4N.Text.DictionaryMatcher::Matches(): Changed count parameter from…
NightOwl888 Nov 17, 2023
9d13619
ICU4N.Globalization.UCultureInfo::ParseTagString(): Converted tags st…
NightOwl888 Nov 17, 2023
5a69a94
ICU4N.Impl.Grego::FloorDivide(): Changed remainder parameter from lon…
NightOwl888 Nov 17, 2023
787c6c9
BREAKING: ICU4N.Impl.Grego (DayToFields() + TimeToFields()): Changed …
NightOwl888 Nov 17, 2023
e5e9c46
ICU4N.Impl.UCharacterName::AddGroupName(): Changed return array to ou…
NightOwl888 Nov 18, 2023
36f9aae
.build/nowarn.props: Disabled LuceneDev1003 and LuceneDev1004 warning…
NightOwl888 Nov 21, 2023
063cac6
ICU4N.Text.TransliteratorIDParser::IDtoSTV(): Converted return array …
NightOwl888 Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ICU4N.Transliterator.Text.TransliteratorIDParser (ParseFilterID() + P…
…arseSingleID() + ParseGlobalFilter()): Changed pos parameter from int[] to ref int (see #57)
  • Loading branch information
NightOwl888 committed Nov 23, 2023
commit 46229ce6f524a5450b7cda19f9afc60d6091b846
108 changes: 56 additions & 52 deletions src/ICU4N.Transliterator/Text/TransliteratorIDParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ internal Transliterator GetInstance()
/// the first character to parse. On output, the position after
/// the last character parsed.</param>
/// <returns>A <see cref="SingleID"/> object or null if the parse fails.</returns>
public static SingleID ParseFilterID(string id, int[] pos)
// ICU4N: Converted pos parameter from int[] to ref int
public static SingleID ParseFilterID(string id, ref int pos)
{

int start = pos[0];
Specs specs = ParseFilterID(id, pos, true);
int start = pos;
Specs specs = ParseFilterID(id, ref pos, true);
if (specs == null)
{
pos[0] = start;
pos = start;
return null;
}

Expand All @@ -173,10 +174,11 @@ public static SingleID ParseFilterID(string id, int[] pos)
/// <param name="dir">The direction. If the direction is <see cref="TransliterationDirection.Reverse"/> then the
/// <see cref="SingleID"/> is constructed for the reverse direction.</param>
/// <returns>A <see cref="SingleID"/> object or null.</returns>
public static SingleID ParseSingleID(string id, int[] pos, TransliterationDirection dir)
// ICU4N: Converted pos parameter from int[] to ref int
public static SingleID ParseSingleID(string id, ref int pos, TransliterationDirection dir)
{

int start = pos[0];
int start = pos;

// The ID will be of the form A, A(), A(B), or (B), where
// A and B are filter IDs.
Expand All @@ -190,23 +192,23 @@ public static SingleID ParseSingleID(string id, int[] pos, TransliterationDirect
{
if (pass == 2)
{
specsA = ParseFilterID(id, pos, true);
specsA = ParseFilterID(id, ref pos, true);
if (specsA == null)
{
pos[0] = start;
pos = start;
return null;
}
}
if (Utility.ParseChar(id, ref pos[0], OPEN_REV))
if (Utility.ParseChar(id, ref pos, OPEN_REV))
{
sawParen = true;
if (!Utility.ParseChar(id, ref pos[0], CLOSE_REV))
if (!Utility.ParseChar(id, ref pos, CLOSE_REV))
{
specsB = ParseFilterID(id, pos, true);
specsB = ParseFilterID(id, ref pos, true);
// Must close with a ')'
if (specsB == null || !Utility.ParseChar(id, ref pos[0], CLOSE_REV))
if (specsB == null || !Utility.ParseChar(id, ref pos, CLOSE_REV))
{
pos[0] = start;
pos = start;
return null;
}
}
Expand Down Expand Up @@ -282,47 +284,48 @@ public static SingleID ParseSingleID(string id, int[] pos, TransliterationDirect
/// indicates a successful parse, regardless of whether the filter
/// applies to the given direction. The caller should discard it
/// if withParens != (dir == <see cref="TransliterationDirection.Reverse"/>).</returns>
public static UnicodeSet ParseGlobalFilter(string id, int[] pos, TransliterationDirection dir,
// ICU4N: Converted pos parameter from int[] to ref int
public static UnicodeSet ParseGlobalFilter(string id, ref int pos, TransliterationDirection dir,
int[] withParens,
StringBuffer canonID)
{
UnicodeSet filter = null;
int start = pos[0];
int start = pos;

if (withParens[0] == -1)
{
withParens[0] = Utility.ParseChar(id, ref pos[0], OPEN_REV) ? 1 : 0;
withParens[0] = Utility.ParseChar(id, ref pos, OPEN_REV) ? 1 : 0;
}
else if (withParens[0] == 1)
{
if (!Utility.ParseChar(id, ref pos[0], OPEN_REV))
if (!Utility.ParseChar(id, ref pos, OPEN_REV))
{
pos[0] = start;
pos = start;
return null;
}
}

pos[0] = PatternProps.SkipWhiteSpace(id, pos[0]);
pos = PatternProps.SkipWhiteSpace(id, pos);

if (UnicodeSet.ResemblesPattern(id, pos[0]))
if (UnicodeSet.ResemblesPattern(id, pos))
{
ParsePosition ppos = new ParsePosition(pos[0]);
ParsePosition ppos = new ParsePosition(pos);
try
{
filter = new UnicodeSet(id, ppos, null);
}
catch (ArgumentException)
{
pos[0] = start;
pos = start;
return null;
}

string pattern = id.Substring(pos[0], ppos.Index - pos[0]); // ICU4N: Corrected 2nd parameter
pos[0] = ppos.Index;
string pattern = id.Substring(pos, ppos.Index - pos); // ICU4N: Corrected 2nd parameter
pos = ppos.Index;

if (withParens[0] == 1 && !Utility.ParseChar(id, ref pos[0], CLOSE_REV))
if (withParens[0] == 1 && !Utility.ParseChar(id, ref pos, CLOSE_REV))
{
pos[0] = start;
pos = start;
return null;
}

Expand Down Expand Up @@ -365,7 +368,7 @@ public static UnicodeSet ParseGlobalFilter(string id, int[] pos, Transliteration
/// <param name="dir">The direction.</param>
/// <param name="canonID">OUTPUT parameter that receives the canonical ID,
/// consisting of canonical IDs for all elements, as returned by
/// <see cref="ParseSingleID(string, int[], TransliterationDirection)"/></param>, separated by semicolons. Previous contents
/// <see cref="ParseSingleID(string, ref int, TransliterationDirection)"/></param>, separated by semicolons. Previous contents
/// are discarded.
/// <param name="list">OUTPUT parameter that receives a list of <see cref="SingleID"/>
/// objects representing the parsed IDs. Previous contents are
Expand All @@ -380,7 +383,7 @@ public static bool ParseCompoundID(string id, TransliterationDirection dir,
IList<SingleID> list,
UnicodeSet[] globalFilter)
{
int[] pos = new int[] { 0 };
int pos = 0;
int[] withParens = new int[1];
list.Clear();
UnicodeSet filter;
Expand All @@ -389,14 +392,14 @@ public static bool ParseCompoundID(string id, TransliterationDirection dir,

// Parse leading global filter, if any
withParens[0] = 0; // parens disallowed
filter = ParseGlobalFilter(id, pos, dir, withParens, canonID);
filter = ParseGlobalFilter(id, ref pos, dir, withParens, canonID);
if (filter != null)
{
if (!Utility.ParseChar(id, ref pos[0], ID_DELIM))
if (!Utility.ParseChar(id, ref pos, ID_DELIM))
{
// Not a global filter; backup and resume
canonID.Length = 0;
pos[0] = 0;
pos = 0;
}
if (dir == Forward)
{
Expand All @@ -407,7 +410,7 @@ public static bool ParseCompoundID(string id, TransliterationDirection dir,
bool sawDelimiter = true;
for (; ; )
{
SingleID single = ParseSingleID(id, pos, dir);
SingleID single = ParseSingleID(id, ref pos, dir);
if (single == null)
{
break;
Expand All @@ -420,7 +423,7 @@ public static bool ParseCompoundID(string id, TransliterationDirection dir,
{
list.Insert(0, single);
}
if (!Utility.ParseChar(id, ref pos[0], ID_DELIM))
if (!Utility.ParseChar(id, ref pos, ID_DELIM))
{
sawDelimiter = false;
break;
Expand Down Expand Up @@ -448,11 +451,11 @@ public static bool ParseCompoundID(string id, TransliterationDirection dir,
if (sawDelimiter)
{
withParens[0] = 1; // parens required
filter = ParseGlobalFilter(id, pos, dir, withParens, canonID);
filter = ParseGlobalFilter(id, ref pos, dir, withParens, canonID);
if (filter != null)
{
// Don't require trailing ';', but parse it if present
Utility.ParseChar(id, ref pos[0], ID_DELIM);
Utility.ParseChar(id, ref pos, ID_DELIM);

if (dir == Reverse)
{
Expand All @@ -462,8 +465,8 @@ public static bool ParseCompoundID(string id, TransliterationDirection dir,
}

// Trailing unparsed text is a syntax error
pos[0] = PatternProps.SkipWhiteSpace(id, pos[0]);
if (pos[0] != id.Length)
pos = PatternProps.SkipWhiteSpace(id, pos);
if (pos != id.Length)
{
return false;
}
Expand Down Expand Up @@ -650,10 +653,10 @@ public static void RegisterSpecialInverse(string target,
/// source of ANY.
/// </summary>
/// <param name="id">The id string, in any of several forms.</param>
/// <param name="pos">INPUT-OUTPUT parameter. On input, pos[0] is the
/// <param name="pos">INPUT-OUTPUT parameter. On input, <paramref name="pos"/> is the
/// offset of the first character to parse in id. On output,
/// pos[0] is the offset after the last parsed character. If the
/// parse failed, pos[0] will be unchanged.</param>
/// <paramref name="pos"/> is the offset after the last parsed character. If the
/// parse failed, <paramref name="pos"/> will be unchanged.</param>
/// <param name="allowFilter">If true, a <see cref="UnicodeSet"/> pattern is allowed
/// at any location between specs or delimiters, and is returned
/// as the fifth string in the array.</param>
Expand All @@ -663,7 +666,8 @@ public static void RegisterSpecialInverse(string target,
/// pattern is returned in the <see cref="Specs"/> object, otherwise the returned
/// filter reference is null. If the parse fails for any reason
/// null is returned.</returns>
private static Specs ParseFilterID(string id, int[] pos,
// ICU4N: Converted pos parameter from int[] to ref int
private static Specs ParseFilterID(string id, ref int pos,
bool allowFilter)
{
string first = null;
Expand All @@ -673,40 +677,40 @@ private static Specs ParseFilterID(string id, int[] pos,
string filter = null;
char delimiter = (char)0;
int specCount = 0;
int start = pos[0];
int start = pos;

// This loop parses one of the following things with each
// pass: a filter, a delimiter character (either '-' or '/'),
// or a spec (source, target, or variant).
for (; ; )
{
pos[0] = PatternProps.SkipWhiteSpace(id, pos[0]);
if (pos[0] == id.Length)
pos = PatternProps.SkipWhiteSpace(id, pos);
if (pos == id.Length)
{
break;
}

// Parse filters
if (allowFilter && filter == null &&
UnicodeSet.ResemblesPattern(id, pos[0]))
UnicodeSet.ResemblesPattern(id, pos))
{

ParsePosition ppos = new ParsePosition(pos[0]);
ParsePosition ppos = new ParsePosition(pos);
// Parse the set to get the position.
new UnicodeSet(id, ppos, null);
filter = id.Substring(pos[0], ppos.Index - pos[0]); // ICU4N: Corrected 2nd parameter
pos[0] = ppos.Index;
filter = id.Substring(pos, ppos.Index - pos); // ICU4N: Corrected 2nd parameter
pos = ppos.Index;
continue;
}

if (delimiter == 0)
{
char c = id[pos[0]];
char c = id[pos];
if ((c == TARGET_SEP && target == null) ||
(c == VARIANT_SEP && variant == null))
{
delimiter = c;
++pos[0];
++pos;
continue;
}
}
Expand All @@ -719,7 +723,7 @@ private static Specs ParseFilterID(string id, int[] pos,
break;
}

string spec = Utility.ParseUnicodeIdentifier(id, ref pos[0]);
string spec = Utility.ParseUnicodeIdentifier(id, ref pos);
if (spec == null)
{
// Note that if there was a trailing delimiter, we
Expand Down Expand Up @@ -761,7 +765,7 @@ private static Specs ParseFilterID(string id, int[] pos,
// Must have either source or target
if (source == null && target == null)
{
pos[0] = start;
pos = start;
return null;
}

Expand Down
28 changes: 14 additions & 14 deletions src/ICU4N.Transliterator/Text/TransliteratorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private int ParseSection(string rule, int pos, int limit,
int quoteLimit = -1;
int varStart = -1; // Most recent $variableReference
int varLimit = -1;
int[] iref = new int[1];
int iref = 0;
int bufStart = buf.Length;

//main:
Expand Down Expand Up @@ -643,11 +643,11 @@ private int ParseSection(string rule, int pos, int limit,
case FUNCTION:
case ALT_FUNCTION:
{
iref[0] = pos;
TransliteratorIDParser.SingleID single = TransliteratorIDParser.ParseFilterID(rule, iref);
iref = pos;
TransliteratorIDParser.SingleID single = TransliteratorIDParser.ParseFilterID(rule, ref iref);
// The next character MUST be a segment open
if (single == null ||
!Utility.ParseChar(rule, ref iref[0], SEGMENT_OPEN))
!Utility.ParseChar(rule, ref iref, SEGMENT_OPEN))
{
SyntaxError("Invalid function", rule, start);
}
Expand All @@ -663,7 +663,7 @@ private int ParseSection(string rule, int pos, int limit,
int bufSegStart = buf.Length;

// Parse the segment
pos = ParseSection(rule, iref[0], limit, parser, buf, ILLEGAL_FUNC, true);
pos = ParseSection(rule, iref, limit, parser, buf, ILLEGAL_FUNC, true);

// After parsing a segment, the relevant characters are
// in buf, starting at offset bufSegStart.
Expand Down Expand Up @@ -695,14 +695,14 @@ private int ParseSection(string rule, int pos, int limit,
int r = UChar.Digit(c, 10);
if (r >= 1 && r <= 9)
{
iref[0] = pos;
r = Utility.ParseNumber(rule, ref iref[0], 10);
iref = pos;
r = Utility.ParseNumber(rule, ref iref, 10);
if (r < 0)
{
SyntaxError("Undefined segment reference",
rule, start);
}
pos = iref[0];
pos = iref;
buf.Append(parser.GetSegmentStandin(r));
}
else
Expand Down Expand Up @@ -1083,7 +1083,7 @@ private void ParseRules(RuleBody ruleArray, TransliterationDirection dir)
++pos;
c = rule[pos];
}
int[] p = new int[] { pos };
int p = pos;

if (!parsingIDs)
{
Expand All @@ -1100,8 +1100,8 @@ private void ParseRules(RuleBody ruleArray, TransliterationDirection dir)

TransliteratorIDParser.SingleID id =
TransliteratorIDParser.ParseSingleID(
rule, p, direction);
if (p[0] != pos && Utility.ParseChar(rule, ref p[0], END_OF_RULE))
rule, ref p, direction);
if (p != pos && Utility.ParseChar(rule, ref p, END_OF_RULE))
{
// Successful ::ID parse.

Expand All @@ -1119,8 +1119,8 @@ private void ParseRules(RuleBody ruleArray, TransliterationDirection dir)
{
// Couldn't parse an ID. Try to parse a global filter
int[] withParens = new int[] { -1 };
UnicodeSet f = TransliteratorIDParser.ParseGlobalFilter(rule, p, direction, withParens, null);
if (f != null && Utility.ParseChar(rule, ref p[0], END_OF_RULE))
UnicodeSet f = TransliteratorIDParser.ParseGlobalFilter(rule, ref p, direction, withParens, null);
if (f != null && Utility.ParseChar(rule, ref p, END_OF_RULE))
{
if ((direction == Transliterator.Forward) ==
(withParens[0] == 0))
Expand All @@ -1142,7 +1142,7 @@ private void ParseRules(RuleBody ruleArray, TransliterationDirection dir)
}
}

pos = p[0];
pos = p;
}
else
{
Expand Down