Skip to content

Commit b943fc3

Browse files
authored
Merge pull request EvilBeaver#1623 from Mr-Rm/v2/fix-1580
V2 EvilBeaver#1580: Ошибки и несоответствия разных методов ТаблицыЗначений
2 parents 140223e + 22c9136 commit b943fc3

File tree

10 files changed

+494
-144
lines changed

10 files changed

+494
-144
lines changed

src/OneScript.Core/Exceptions/RuntimeException.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,22 @@ public static RuntimeException InvalidEncoding(string encoding)
175175
return new RuntimeException(
176176
$"Неправильное имя кодировки '{encoding}'",
177177
$"Invalid encoding name '{encoding}'");
178+
}
179+
180+
public static RuntimeException IncorrectOffset()
181+
{
182+
return new RuntimeException(
183+
"Неправильное смещение внутри коллекции",
184+
"Incorrect offset within collection");
185+
}
186+
187+
public static RuntimeException IndexOutOfRange()
188+
{
189+
return new RuntimeException(
190+
"Значение индекса выходит за пределы диапазона",
191+
"Index is out of range");
178192
}
179-
193+
180194
#endregion
181195
}
182196
}

src/OneScript.Language/Localization/BilingualString.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,15 @@ public static string Localize(string russian, string english)
7373

7474
return russian;
7575
}
76+
}
77+
78+
public static class BilingualStringExtension
79+
{
80+
public static bool BilingualEquals(this string str, string lang1, string lang2,
81+
StringComparison comparison = StringComparison.CurrentCultureIgnoreCase)
82+
{
83+
return string.Equals(str, lang1, comparison) || string.Equals(str, lang2, comparison);
84+
}
7685
}
86+
7787
}

src/OneScript.StandardLibrary/Binary/BinaryDataBuffer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void WriteInt64(int position, BslValue value, BslValue byteOrder = null)
246246
private void WriteBitwiseOp(int position, BinaryDataBuffer buffer, int number, Func<byte, byte, byte> op)
247247
{
248248
if(position < 0)
249-
throw new IndexOutOfRangeException("Значение индекса выходит за границы диапазона");
249+
throw RuntimeException.IndexOutOfRange();
250250

251251
try
252252
{

src/OneScript.StandardLibrary/Collections/ArrayImpl.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void Add(IValue value = null)
9999
public void Insert(int index, IValue value = null)
100100
{
101101
if (index < 0)
102-
throw IndexOutOfBoundsException();
102+
throw RuntimeException.IndexOutOfRange();
103103

104104
if (index > _values.Count)
105105
Extend(index - _values.Count);
@@ -128,7 +128,7 @@ public IValue Find(IValue what)
128128
public void Remove(int index)
129129
{
130130
if (index < 0 || index >= _values.Count)
131-
throw IndexOutOfBoundsException();
131+
throw RuntimeException.IndexOutOfRange();
132132

133133
_values.RemoveAt(index);
134134
}
@@ -143,7 +143,7 @@ public int UpperBound()
143143
public IValue Get(int index)
144144
{
145145
if (index < 0 || index >= _values.Count)
146-
throw IndexOutOfBoundsException();
146+
throw RuntimeException.IndexOutOfRange();
147147

148148
return _values[index];
149149
}
@@ -152,7 +152,7 @@ public IValue Get(int index)
152152
public void Set(int index, IValue value)
153153
{
154154
if (index < 0 || index >= _values.Count)
155-
throw IndexOutOfBoundsException();
155+
throw RuntimeException.IndexOutOfRange();
156156

157157
_values[index] = value;
158158
}
@@ -234,10 +234,5 @@ public static ArrayImpl Constructor(FixedArrayImpl fixedArray)
234234
{
235235
return new ArrayImpl(fixedArray);
236236
}
237-
238-
private static RuntimeException IndexOutOfBoundsException()
239-
{
240-
return new RuntimeException("Значение индекса выходит за пределы диапазона");
241-
}
242237
}
243238
}

src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private int IndexByValue(BslValue item)
212212
}
213213

214214
if (index < 0 || index >= _items.Count())
215-
throw new RuntimeException("Значение индекса выходит за пределы диапазона");
215+
throw RuntimeException.IndexOutOfRange();
216216
}
217217

218218
return index;

0 commit comments

Comments
 (0)