Skip to content

Commit 1fd097a

Browse files
committed
Prep for 1.5 A3 release
1 parent 2328604 commit 1fd097a

File tree

6 files changed

+205
-87
lines changed

6 files changed

+205
-87
lines changed

CardMaker/Card/Translation/InceptTranslator.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using System.Linq;
2929
using System.Text;
3030
using System.Text.RegularExpressions;
31+
using CardMaker.Card.FormattedText.Util;
3132
using CardMaker.Data;
3233
using CardMaker.Events.Managers;
3334
using CardMaker.XML;
@@ -78,6 +79,9 @@ private enum LogicCheck
7879
private static readonly Regex s_regexIfSet = new Regex(@"(\[)(.*?)(\])", RegexOptions.Compiled);
7980
private static readonly Regex s_regexSwitchStatement = new Regex(@"(switch)(;)(.*?)(;)(.*)", RegexOptions.Compiled);
8081
private static readonly Regex s_regexPadStatement = new Regex(@"(.*)(#pad)([l|r])(;)(\d+)(;)(\d+)(;)(.*?)(#)(.*)", RegexOptions.Compiled);
82+
private static readonly Regex s_regexCaps = new Regex(@"(.*)(#\(caps)(;)(.*?)(\)#)(.*)", RegexOptions.Compiled);
83+
private static readonly Regex s_regexNoCaps = new Regex(@"(.*)(#\(nocaps)(;)(.*?)(\)#)(.*)", RegexOptions.Compiled);
84+
private static readonly Regex s_regexTitleCase = new Regex(@"(.*)(#\(titlecase)(;)(.*?)(\)#)(.*)", RegexOptions.Compiled);
8185

8286
private const string SWITCH = "switch";
8387

@@ -155,6 +159,11 @@ protected override ElementString TranslateToElementString(Deck zDeck, string sRa
155159
// Translate element fields
156160
sOutput = LoopTranslateRegex(s_regexElementFields, sOutput, zTranslationContext, TranslateElementFields);
157161

162+
// Translate capitalization
163+
sOutput = LoopTranslateRegex(s_regexCaps, sOutput, zTranslationContext, TranslateCaps);
164+
sOutput = LoopTranslateRegex(s_regexNoCaps, sOutput, zTranslationContext, TranslateNoCaps);
165+
sOutput = LoopTranslateRegex(s_regexTitleCase, sOutput, zTranslationContext, TranslateTitleCase);
166+
158167
// Translate string length
159168
sOutput = LoopTranslateRegex(s_regexStringLength, sOutput, zTranslationContext, TranslateStringLength);
160169

@@ -586,6 +595,42 @@ private string TranslateElementFields(Match zMatch, TranslationContext zTranslat
586595
return zMatch.Groups[1].Value + sTranslated + zMatch.Groups[5].Value;
587596
}
588597

598+
private string TranslateCaps(Match zMatch, TranslationContext zTranslationContext)
599+
{
600+
// Override evaluation:
601+
// Translate element fields
602+
// Groups
603+
// 1 2 3 4 5 6
604+
// @"(.*)(#\(caps)(;)(.*?)(\)#)(.*)"
605+
var sTranslated = zMatch.Groups[4].ToString().ToUpper(CultureInfo.CurrentCulture);
606+
607+
return zMatch.Groups[1].Value + sTranslated + zMatch.Groups[6].Value;
608+
}
609+
610+
private string TranslateNoCaps(Match zMatch, TranslationContext zTranslationContext)
611+
{
612+
// Override evaluation:
613+
// Translate element fields
614+
// Groups
615+
// 1 2 3 4 5 6
616+
// @"(.*)(#\(nocaps)(;)(.*?)(\)#)(.*)"
617+
var sTranslated = zMatch.Groups[4].ToString().ToLower(CultureInfo.CurrentCulture);
618+
619+
return zMatch.Groups[1].Value + sTranslated + zMatch.Groups[6].Value;
620+
}
621+
622+
private string TranslateTitleCase(Match zMatch, TranslationContext zTranslationContext)
623+
{
624+
// Override evaluation:
625+
// Translate element fields
626+
// Groups
627+
// 1 2 3 4 5 6
628+
// @"(.*)(#\(titlecase)(;)(.*?)(\)#)(.*)"
629+
var sTranslated = StringUtil.ConvertToTitleCase(zMatch.Groups[4].ToString());
630+
631+
return zMatch.Groups[1].Value + sTranslated + zMatch.Groups[6].Value;
632+
}
633+
589634
private string TranslateOverrides(Match zMatch, TranslationContext zTranslationContext)
590635
{
591636
// Override evaluation:

CardMaker/CardMakerBuild.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class CardMakerBuild
3131
public static string GetBuildSuffix()
3232
{
3333
#if UNSTABLE
34-
return "[UNSTABLE] V.A2";
34+
return "[UNSTABLE] V.A3";
3535
#else
3636
return string.Empty;
3737
#endif

CardMaker/Test/UnitTest/Card/FormattedText/Util/StringUtilTests.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
using CardMaker.Card.FormattedText.Util;
1+
////////////////////////////////////////////////////////////////////////////////
2+
// The MIT License (MIT)
3+
//
4+
// Copyright (c) 2024 Tim Stair
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in all
14+
// copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
// SOFTWARE.
23+
////////////////////////////////////////////////////////////////////////////////
24+
25+
using CardMaker.Card.FormattedText.Util;
226
using NUnit.Framework;
327

428
namespace UnitTest.Card.FormattedText.Util

CardMaker/Test/UnitTest/DeckObject/InceptStringTranslation.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using NUnit.Framework;
2727
using System;
2828
using System.Collections.Generic;
29+
using System.Diagnostics;
2930
using System.Drawing;
3031
using CardMaker.Data;
3132
using Moq;
@@ -150,6 +151,54 @@ public string ValidateElementFields(string input)
150151
return result.String;
151152
}
152153

154+
[TestCase("#(caps;)#", ExpectedResult = "")]
155+
[TestCase("#(caps;A)#", ExpectedResult = "A")]
156+
[TestCase("#(caps;a)#", ExpectedResult = "A")]
157+
[TestCase("#(caps;abc)#", ExpectedResult = "ABC")]
158+
[TestCase("#(caps;ABC)#", ExpectedResult = "ABC")]
159+
[TestCase("xy#(caps;abc)#zy", ExpectedResult = "xyABCzy")]
160+
[TestCase("xy#(caps;ABC)#zy", ExpectedResult = "xyABCzy")]
161+
public string ValidateCaps(string input)
162+
{
163+
_testDeck.ProcessLinesPublic(new List<List<string>>(), new List<List<string>>(), "test");
164+
var result = _testDeck.TranslateString(input, _testDeck.CurrentLine, _testElement);
165+
return result.String;
166+
}
167+
168+
[TestCase("#(nocaps;)#", ExpectedResult = "")]
169+
[TestCase("#(nocaps;A)#", ExpectedResult = "a")]
170+
[TestCase("#(nocaps;a)#", ExpectedResult = "a")]
171+
[TestCase("#(nocaps;abc)#", ExpectedResult = "abc")]
172+
[TestCase("#(nocaps;ABC)#", ExpectedResult = "abc")]
173+
[TestCase("xy#(nocaps;abc)#zy", ExpectedResult = "xyabczy")]
174+
[TestCase("xy#(nocaps;ABC)#zy", ExpectedResult = "xyabczy")]
175+
public string ValidateNoCaps(string input)
176+
{
177+
_testDeck.ProcessLinesPublic(new List<List<string>>(), new List<List<string>>(), "test");
178+
var result = _testDeck.TranslateString(input, _testDeck.CurrentLine, _testElement);
179+
return result.String;
180+
}
181+
182+
183+
[TestCase("#(titlecase;)#", ExpectedResult = "")]
184+
[TestCase("#(titlecase;\t)#", ExpectedResult = "\t")]
185+
[TestCase("#(titlecase;\ta)#", ExpectedResult = "\tA")]
186+
[TestCase("#(titlecase;\ta\tb)#", ExpectedResult = "\tA\tB")]
187+
[TestCase("#(titlecase;a\tb)#", ExpectedResult = "A\tB")]
188+
[TestCase("#(titlecase;alpha beta gamma)#", ExpectedResult = "Alpha Beta Gamma")]
189+
[TestCase("#(titlecase;1alpha 2beta 3gamma)#", ExpectedResult = "1alpha 2beta 3gamma")]
190+
[TestCase("#(titlecase;-alpha =beta !gamma)#", ExpectedResult = "-alpha =beta !gamma")]
191+
[TestCase("#(titlecase;alpha,beta, gamma)#", ExpectedResult = "Alpha,beta, Gamma")]
192+
[TestCase("#(titlecase;Alpha Beta Gamma)#", ExpectedResult = "Alpha Beta Gamma")]
193+
[TestCase("00#(titlecase;Alpha Beta Gamma\t )#11", ExpectedResult = "00Alpha Beta Gamma\t 11")]
194+
[TestCase(" 00 #(titlecase;ALPHA BETA gAmma\t )#11 ", ExpectedResult = " 00 Alpha Beta Gamma\t 11 ")]
195+
public string ValidateTitleCase(string input)
196+
{
197+
_testDeck.ProcessLinesPublic(new List<List<string>>(), new List<List<string>>(), "test");
198+
var result = _testDeck.TranslateString(input, _testDeck.CurrentLine, _testElement);
199+
return result.String;
200+
}
201+
153202
[TestCase("aa#padl;5;0;123#bb", ExpectedResult = "aa00123bb")]
154203
[TestCase("aa#padr;5;0;123#bb", ExpectedResult = "aa12300bb")]
155204
[TestCase("aa#padl;3;0;123#bb", ExpectedResult = "aa123bb")]
304 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)