Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -329,50 +329,65 @@ internal static WordsCollection Parse(List<SDLXLIFF.SegmentSection> xSegmentSect
else
{

while (curPos < xSegmentSection.Content.Length)
{
var prevPos = curPos;
while (curPos < xSegmentSection.Content.Length &&
(char.IsControl(xSegmentSection.Content[curPos])
|| char.IsWhiteSpace(xSegmentSection.Content[curPos])))
{
curPos++;
}
prefix += xSegmentSection.Content.Substring(prevPos, curPos - prevPos);

if (curPos == xSegmentSection.Content.Length)
{

if (prefix != string.Empty)
{
words.Add(new Word(string.Empty, prefix, string.Empty));
}
break;
}

prevPos = curPos;
while (curPos < xSegmentSection.Content.Length &&
!char.IsControl(xSegmentSection.Content[curPos]) &&
!char.IsWhiteSpace(xSegmentSection.Content[curPos]))
{
curPos++;
}
var word = xSegmentSection.Content.Substring(prevPos, curPos - prevPos);


prevPos = curPos;
while (curPos < xSegmentSection.Content.Length &&
(char.IsControl(xSegmentSection.Content[curPos]) ||
char.IsWhiteSpace(xSegmentSection.Content[curPos])))
{
curPos++;
}
suffix = xSegmentSection.Content.Substring(prevPos, curPos - prevPos);
ProcessWord(words, prefix, word, suffix);
prefix = string.Empty;
}
}
}
while (curPos < xSegmentSection.Content.Length)
{
var prevPos = curPos;
while (curPos < xSegmentSection.Content.Length &&
xSegmentSection.Content[curPos] != '\xa0' && // stop at nbsp
(char.IsControl(xSegmentSection.Content[curPos])
|| char.IsWhiteSpace(xSegmentSection.Content[curPos])))
{
curPos++;
}
prefix += xSegmentSection.Content.Substring(prevPos, curPos - prevPos);

if (curPos == xSegmentSection.Content.Length)
{

if (prefix != string.Empty)
{
words.Add(new Word(string.Empty, prefix, string.Empty));
}
break;
}

prevPos = curPos;

if (xSegmentSection.Content[curPos] == '\xa0') // make nbsp a word
{
// a word may be a string of non-breaking spaces ...
while (xSegmentSection.Content[curPos] == '\xa0')
{
curPos++;
}
}
else
{
// ... or a string of non-whitespace/non-control
while (curPos < xSegmentSection.Content.Length &&
!char.IsControl(xSegmentSection.Content[curPos]) &&
!char.IsWhiteSpace(xSegmentSection.Content[curPos]))
{
curPos++;
}
}
var word = xSegmentSection.Content.Substring(prevPos, curPos - prevPos);


prevPos = curPos;
while (curPos < xSegmentSection.Content.Length &&
xSegmentSection.Content[curPos] != '\xa0' && // stop at nbsp
(char.IsControl(xSegmentSection.Content[curPos]) ||
char.IsWhiteSpace(xSegmentSection.Content[curPos])))
{
curPos++;
}
suffix = xSegmentSection.Content.Substring(prevPos, curPos - prevPos);
ProcessWord(words, prefix, word, suffix);
prefix = string.Empty;
}
}
}
return words;
}

Expand Down
11 changes: 10 additions & 1 deletion StudioViews/StudioViews/Services/ProjectFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,16 @@ public List<ProjectFileInfo> GetProjectFiles(string filePath)

try
{
var xml = XDocument.Load(filePath, LoadOptions.PreserveWhitespace);
//var xml = XDocument.Load(filePath, LoadOptions.PreserveWhitespace);
XDocument xml = null;
// avoid System.Xml.XmlException Message: '?', hexadecimal value 0x1C, 0x1E, ... is an invalid character.
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings { CheckCharacters = false };
using (XmlReader xmlReader = XmlReader.Create(filePath, xmlReaderSettings))
{
xmlReader.MoveToContent();
xml = XDocument.Load(xmlReader, LoadOptions.PreserveWhitespace);
}

var xliff = xml.Root;
if (xliff != null &&
string.Compare(xliff.Name.LocalName, "xliff", StringComparison.InvariantCultureIgnoreCase) == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,9 @@ private ExportResult ExportFiles(IReadOnlyCollection<ProjectFile> projectFiles,
InputFiles = new List<string>(projectFiles.Select(a => a.LocalFilePath))
};

var sourceLanguage = projectFiles.FirstOrDefault()?.SourceFile.Language.CultureInfo;
var targetLanguage = projectFiles.FirstOrDefault()?.Language.CultureInfo;
// UNNECESSARY AND POSSIBLY A SOURCE FOR ERROR: SourceFile might be null in a WorldServer project
//var sourceLanguage = projectFiles.FirstOrDefault()?.SourceFile.Language.CultureInfo;
//var targetLanguage = projectFiles.FirstOrDefault()?.Language.CultureInfo;

foreach (var documentFile in projectFiles)
{
Expand Down