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
ICU4N.Text.TransliteratorIDParser::IDtoSTV(): Converted return array …
…to out parameters
  • Loading branch information
NightOwl888 committed Nov 23, 2023
commit 063cac62d54b0dabfa94ad19ab7f4604a92d3e1f
22 changes: 12 additions & 10 deletions src/ICU4N.Transliterator/Text/Transliterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,16 +1301,18 @@ public static string GetDisplayName(string id, UCultureInfo inLocale)
GetBundleInstance(ICUData.IcuTransliteratorBaseName, inLocale, ICUResourceBundle.IcuDataAssembly);

// Normalize the ID
string[] stv = TransliteratorIDParser.IDtoSTV(id);
if (stv == null)
TransliteratorIDParser.IDtoSTV(id, out string source, out string target, out string variant, out bool _);
// ICU4N specific - since we are not returning an array, it cannot be null (and it was never null anyway)

// ICU4N specific - use Concat
string ID;
if (!string.IsNullOrEmpty(variant))
{
// No target; malformed id
return "";
ID = string.Concat(source, "-", target, "/", variant);
}
string ID = stv[0] + '-' + stv[1];
if (stv[2] != null && stv[2].Length > 0)
else
{
ID = ID + '/' + stv[2];
ID = string.Concat(source, "-", target);
}

// Use the registered display name, if any
Expand All @@ -1335,7 +1337,7 @@ public static string GetDisplayName(string id, UCultureInfo inLocale)
bundle.GetString(RB_DISPLAY_NAME_PATTERN));

// Construct the argument array
object[] args = new object[] { 2, stv[0], stv[1] };
object[] args = new object[] { 2, source, target };

// Use display names for the scripts, if they exist
for (int j = 1; j <= 2; ++j)
Expand All @@ -1349,8 +1351,8 @@ public static string GetDisplayName(string id, UCultureInfo inLocale)
}

// Format it using the pattern in the resource
return (stv[2].Length > 0) ?
(format.Format(args) + '/' + stv[2]) :
return (variant.Length > 0) ?
(format.Format(args) + '/' + variant) :
format.Format(args);
}
catch (MissingManifestResourceException) { }
Expand Down
24 changes: 11 additions & 13 deletions src/ICU4N.Transliterator/Text/TransliteratorIDParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,24 +522,25 @@ internal static IList<Transliterator> InstantiateList(IList<SingleID> ids)
/// ANY.
/// </summary>
/// <param name="id">The id string, in any of several forms.</param>
/// <returns>An array of 4 strings: source, target, variant, and
/// isSourcePresent. If the source is not present, ANY will be
/// given as the source, and isSourcePresent will be null. Otherwise
/// isSourcePresent will be non-null. The target may be empty if the
/// id is not well-formed. The variant may be empty.</returns>
public static string[] IDtoSTV(string id)
/// <param name="source">When this method returns, provides the source from the <paramref name="id"/>.</param>
/// <param name="target">When this method returns, provides the target from the <paramref name="id"/>.
/// The target may be empty if the id is not well-formed.</param>
/// <param name="variant">When this method returns, provides the variant from the <paramref name="id"/>.
/// The variant may be empty.</param>
/// <param name="isSourcePresent">When this method returns, provides a boolean value indicating whether source is present.</param>
public static void IDtoSTV(string id, out string source, out string target, out string variant, out bool isSourcePresent)
{
string source = ANY;
string target = null;
string variant = "";
source = ANY;
target = null;
variant = "";

int sep = id.IndexOf(TARGET_SEP);
int var = id.IndexOf(VARIANT_SEP);
if (var < 0)
{
var = id.Length;
}
bool isSourcePresent = false;
isSourcePresent = false;

if (sep < 0)
{
Expand Down Expand Up @@ -574,9 +575,6 @@ public static string[] IDtoSTV(string id)
{
variant = variant.Substring(1);
}

return new string[] { source, target, variant,
isSourcePresent ? "" : null };
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions src/ICU4N.Transliterator/Text/TransliteratorRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ public virtual void Put(string id,
/// </summary>
public virtual void Remove(string id)
{
string[] stv = TransliteratorIDParser.IDtoSTV(id);
TransliteratorIDParser.IDtoSTV(id, out string stv0, out string stv1, out string stv2, out bool _);
// Only need to do this if ID.indexOf('-') < 0
string id2 = TransliteratorIDParser.STVtoID(stv[0], stv[1], stv[2]);
string id2 = TransliteratorIDParser.STVtoID(stv0, stv1, stv2);
registry.Remove(new CaseInsensitiveString(id2));
RemoveSTV(stv[0], stv[1], stv[2]);
RemoveSTV(stv0, stv1, stv2);
availableIDs.Remove(new CaseInsensitiveString(id2));
}

Expand Down Expand Up @@ -540,10 +540,10 @@ private void RegisterEntry(string ID,
object entry,
bool visible)
{
string[] stv = TransliteratorIDParser.IDtoSTV(ID);
TransliteratorIDParser.IDtoSTV(ID, out string stv0, out string stv1, out string stv2, out bool _);
// Only need to do this if ID.indexOf('-') < 0
string id = TransliteratorIDParser.STVtoID(stv[0], stv[1], stv[2]);
RegisterEntry(id, stv[0], stv[1], stv[2], entry, visible);
string id = TransliteratorIDParser.STVtoID(stv0, stv1, stv2);
RegisterEntry(id, stv0, stv1, stv2, entry, visible);
}

/// <summary>
Expand Down Expand Up @@ -822,8 +822,8 @@ private object[] FindInBundle(Spec specToOpen,
/// <returns></returns>
private object[] Find(string ID)
{
string[] stv = TransliteratorIDParser.IDtoSTV(ID);
return Find(stv[0], stv[1], stv[2]);
TransliteratorIDParser.IDtoSTV(ID, out string stv0, out string stv1, out string stv2, out bool _);
return Find(stv0, stv1, stv2);
}

/// <summary>
Expand Down