[gnome-subtitles] Round up when splitting a subtitle's text in 2.
- From: Pedro Daniel da Rocha Melo e Castro <pcastro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-subtitles] Round up when splitting a subtitle's text in 2.
- Date: Sun, 12 Jun 2011 22:50:30 +0000 (UTC)
commit e8f8f2c0cbc45f67b274d91cdaf9ee282d4a1191
Author: Pedro Castro <mail pedrocastro org>
Date: Sun Jun 12 23:50:15 2011 +0100
Round up when splitting a subtitle's text in 2.
src/SubLib/Core/Timing/SplitOperator.cs | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/src/SubLib/Core/Timing/SplitOperator.cs b/src/SubLib/Core/Timing/SplitOperator.cs
index 7aa243a..4cdf23c 100644
--- a/src/SubLib/Core/Timing/SplitOperator.cs
+++ b/src/SubLib/Core/Timing/SplitOperator.cs
@@ -104,13 +104,30 @@ public class SplitOperator {
}
private void SplitArray<T> (T[] array, ref T[] half1, ref T[] half2) {
+ if (array == null) {
+ half1 = null;
+ half2 = null;
+ return;
+ }
+
int arrayLength = array.Length;
- int half1Length = arrayLength / 2;
- int half2Length = arrayLength - half1Length;
- half1 = new T[half1Length];
- half2 = new T[half2Length];
- Array.Copy(array, 0, half1, 0, half1Length);
- Array.Copy(array, half1Length, half2, 0, half2Length);
+ if (arrayLength == 0) {
+ half1 = new T[0];
+ half2 = new T[0];
+ }
+ else if (arrayLength == 1) {
+ half1 = new T[1];
+ half1[0] = array[0];
+ half2 = new T[0];
+ }
+ else {
+ int half1Length = (int)Math.Round(arrayLength / 2d);
+ int half2Length = arrayLength - half1Length;
+ half1 = new T[half1Length];
+ half2 = new T[half2Length];
+ Array.Copy(array, 0, half1, 0, half1Length);
+ Array.Copy(array, half1Length, half2, 0, half2Length);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]