Skip to content

Commit

Permalink
Fixed missing empty lines in notes (fix #522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Jan 23, 2024
1 parent 1f59466 commit 9e80dfc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Fixed missing empty lines in notes.
<li>Fixed an error in attaching unknown (and webp) multimedia files.
<li>Added columns for signs of the presence of multimedia, notes and sources to the lists of events/facts.
<li>Added a call to quickly view information in the record selection dialog (list pop-up menu).
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>??.??.2024 [v2.29.0 &amp; v3.5.0]</b><ul>
<li>Исправлены отсутствующие пустые строки в заметках.
<li>Исправлена ошибка присоединения неизвестных (и webp) мультимедиа файлов.
<li>Добавлены столбцы признаков наличия мультимедиа, заметок и источников в списки событий/фактов.
<li>Добавлен вызов быстрого просмотра информации в диалог выбора записей (всплывающее меню списка).
Expand Down
11 changes: 9 additions & 2 deletions projects/GKCore/GDModel/GDMLines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public void Assign(GDMLines source)
/// <summary>
/// A function for safely platform-independent string splitting by newlines.
/// Because in some UI (Eto.Forms) string on Windows may come with '\n' delimiter instead of '\r\n'.
///
/// Variants: \n - Unix & Unix-like (including MacOSX aka macOS?), \r\n - Windows, \r - classic MacOS before 2001.
/// </summary>
private void ParseLine(string line)
{
Expand All @@ -97,19 +99,24 @@ private void ParseLine(string line)

int inPos = 0, inLen = line.Length;
int outPos = 0, outLen = 0;
bool wasLF = false;
while (true) {
char ch = (inPos >= inLen) ? '\0' : line[inPos];
inPos += 1;

if (ch == '\r' || ch == '\n' || ch == '\0') {
if (outLen > 0) {
if (ch == '\n' || ch == '\0') {
if (outLen > 0 || wasLF) {
string piece = line.Substring(outPos, outLen);
Add(piece);
}
outPos = inPos;
outLen = 0;
wasLF = true;
} else if (ch == '\r') {
// skipped
} else {
outLen += 1;
wasLF = false;
}

if (ch == '\0') break;
Expand Down
48 changes: 35 additions & 13 deletions projects/GKTests/GDModel/GDMLinesTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2021 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -49,18 +49,6 @@ public void Test_Common()

Assert.AreEqual("The\r\nstring\r\nlist\r\ntest", strList.Text);

var strList1 = new GDMLines("The\r\nstring\r\nlist\r\ntest");
Assert.AreEqual("The", strList1[0]);
Assert.AreEqual("string", strList1[1]);
Assert.AreEqual("list", strList1[2]);
Assert.AreEqual("test", strList1[3]);

strList1 = new GDMLines("The1\nstring1\nlist1\ntest1");
Assert.AreEqual("The1", strList1[0]);
Assert.AreEqual("string1", strList1[1]);
Assert.AreEqual("list1", strList1[2]);
Assert.AreEqual("test1", strList1[3]);

GDMLines strList2 = new GDMLines();
strList2.Assign(null);
strList2.Assign(strList);
Expand Down Expand Up @@ -102,5 +90,39 @@ public void Test_Common()
string[] strArr = null;
Assert.Throws(typeof(ArgumentNullException), () => { strList.AddRange(strArr); });
}

[Test]
public void Test_CRLF()
{
var strList1 = new GDMLines("The\r\nstring\r\n\r\nlist\r\ntest");
Assert.AreEqual("The", strList1[0]);
Assert.AreEqual("string", strList1[1]);
Assert.AreEqual("", strList1[2]);
Assert.AreEqual("list", strList1[3]);
Assert.AreEqual("test", strList1[4]);
}

[Test]
public void Test_LFOnly()
{
var strList1 = new GDMLines("The1\nstring1\n\nlist1\ntest1");
Assert.AreEqual("The1", strList1[0]);
Assert.AreEqual("string1", strList1[1]);
Assert.AreEqual("", strList1[2]);
Assert.AreEqual("list1", strList1[3]);
Assert.AreEqual("test1", strList1[4]);
}

[Test]
public void Test_EmptyLines()
{
var strList = new GDMLines();
strList.Text = "The string\r\n\r\n list test";
Assert.AreEqual("The string\r\n\r\n list test", strList.Text);

Assert.AreEqual("The string", strList[0]);
Assert.AreEqual("", strList[1]);
Assert.AreEqual(" list test", strList[2]);
}
}
}

0 comments on commit 9e80dfc

Please sign in to comment.