From cab64f6534d49db3b784eb87df9bcffd8dc07be8 Mon Sep 17 00:00:00 2001 From: xulihang Date: Tue, 1 Sep 2020 22:39:51 +0800 Subject: [PATCH] do not check if XmlNode contains only text when updating its content --- BasicCAT/BasicCAT.b4j | 48 ++++++++++++++++---------------- BasicCAT/BasicCAT.b4j.meta | 4 +-- BasicCAT/Utils.bas | 8 +++--- BasicCAT/XMLUtils.bas | 11 ++++++-- BasicCAT/XmlNode.bas | 56 ++++++++++++++++---------------------- 5 files changed, 61 insertions(+), 66 deletions(-) diff --git a/BasicCAT/BasicCAT.b4j b/BasicCAT/BasicCAT.b4j index 223c7ce..cdc54bb 100644 --- a/BasicCAT/BasicCAT.b4j +++ b/BasicCAT/BasicCAT.b4j @@ -187,33 +187,33 @@ Library8=jrandomaccessfile Library9=jb4xencryption Module1=FileChooserUtils Module10=preTranslateDialog -Module11=xliffFilter -Module12=TMX -Module13=XmlNode +Module11=TMX +Module12=XMLUtils +Module13=MT Module14=SimpleTag -Module15=XMLUtils -Module16=XmlParser -Module17=XMLBuilder2 -Module18=Utils -Module19=idmlFilter +Module15=XmlNode +Module16=xliffFilter +Module17=XmlParser +Module18=XMLBuilder2 +Module19=Utils Module2=Project -Module20=statistics -Module21=TMDB -Module22=RichTextArea -Module23=Xml2Map -Module24=importDialog -Module25=TMManager -Module26=tikal -Module27=editDistance -Module28=pdfbox -Module29=Preferences +Module20=idmlFilter +Module21=statistics +Module22=TMDB +Module23=RichTextArea +Module24=Xml2Map +Module25=importDialog +Module26=TMManager +Module27=tikal +Module28=editDistance +Module29=pdfbox Module3=segmentation -Module30=idmlUtils -Module31=filterGenericUtils -Module32=SourceTextEditor -Module33=Previewer -Module34=git -Module35=MT +Module30=Preferences +Module31=idmlUtils +Module32=filterGenericUtils +Module33=SourceTextEditor +Module34=Previewer +Module35=git Module36=TagKind Module37=PathSaver Module38=SearchView diff --git a/BasicCAT/BasicCAT.b4j.meta b/BasicCAT/BasicCAT.b4j.meta index a73b3d9..a8b4679 100644 --- a/BasicCAT/BasicCAT.b4j.meta +++ b/BasicCAT/BasicCAT.b4j.meta @@ -226,6 +226,6 @@ ModuleClosedNodes74= ModuleClosedNodes75= ModuleClosedNodes8= ModuleClosedNodes9= -NavigationStack=XmlNode,setinnerText,98,2,SimpleTag,HasClosingBackquote,129,0,XMLUtils,isXLIFFTag,359,0,XMLUtils,DiscloseTagText,409,0,XMLUtils,XMLToText,413,1,TMX,removeTMXTags,93,0,XMLUtils,EncloseTagText,368,6,TMX,getSegText,85,6,MT,getMT,29,0,TMX,export,157,2 +NavigationStack=filterGenericUtils,tagsAreAPair,180,0,filterGenericUtils,areTagsMatch,108,0,filterGenericUtils,tagsNum,129,0,xliffFilter,addNecessaryTags,435,0,idmlFilter,shouldAddSpace,700,0,xliffFilter,shouldAddSpace,460,0,xliffFilter,generateFile,260,0,filterGenericUtils,joinSegments,109,0,filterGenericUtils,relaceAtTheRightPosition,65,0,Utils,splitByFind,71,0 SelectedBuild=0 -VisibleModules=1,2,3,4,5,6,7,8,9,10,12,15,35,14,13 +VisibleModules=1,2,3,4,5,6,7,8,9,10,15,16,12,19,32,20,34,65,59 diff --git a/BasicCAT/Utils.bas b/BasicCAT/Utils.bas index fadfa40..7781fd3 100644 --- a/BasicCAT/Utils.bas +++ b/BasicCAT/Utils.bas @@ -71,15 +71,15 @@ Sub splitByFind(text As String,find As String,textSegments As List) Dim length As Int length=text.Length-find.Length For i=0 To length - Log(i) + 'Log(i) Dim endIndex As Int endIndex=i+find.Length currentSegment=text.SubString2(i,endIndex) - Log(currentSegment) + 'Log(currentSegment) If currentSegment=find Then - Log(True) + 'Log(True) Dim textBefore As String - Log(textLeft) + 'Log(textLeft) textBefore=textLeft.SubString2(0,textLeft.IndexOf(find)) If textBefore<>"" Then textSegments.Add(textBefore) diff --git a/BasicCAT/XMLUtils.bas b/BasicCAT/XMLUtils.bas index 95ddc3a..8f48681 100644 --- a/BasicCAT/XMLUtils.bas +++ b/BasicCAT/XMLUtils.bas @@ -411,8 +411,13 @@ Public Sub EncloseTagText(s As String,XMLEscaped As Boolean) As String End Sub '`<g id="1">` -> <g id="1"> -Public Sub DiscloseTagText(s As String) As String - Return Regex.Replace("`(<.*?>)`",s,"$1") +Public Sub DiscloseTagText(s As String,escaped As Boolean) As String + If escaped Then + Return Regex.Replace("`(<.*?>)`",s,"$1") + Else + Return Regex.Replace("`(<.*?>)`",s,"$1") + End If + End Sub Sub XMLToText(xml As String) As String @@ -426,7 +431,7 @@ Sub TextToXML(s As String) As String 'escape: &->& 'xliff tags not escaped except they are enclosed with `` Dim Xml As String=HandleXMLEntities(s,True) 'disclose tags: `<g>` -> <g> - Xml=DiscloseTagText(Xml) + Xml=DiscloseTagText(Xml,True) Return Xml End Sub diff --git a/BasicCAT/XmlNode.bas b/BasicCAT/XmlNode.bas index 109e823..9837940 100644 --- a/BasicCAT/XmlNode.bas +++ b/BasicCAT/XmlNode.bas @@ -74,38 +74,31 @@ End Sub Public Sub setinnerXML(xml As String) Dim parser As XmlParser parser.Initialize - Dim node As XmlNode - Try - node=parser.Parse(xml) - Catch - 'Log(LastException.Message) - Dim sb As StringBuilder - sb.Initialize - sb.Append("<").Append(Name).Append(">") - sb.append(xml) - sb.Append("") - node=parser.Parse(sb.ToString) - 'Log("-------") - 'Log(sb.ToString) - 'Log(node.Name) - 'Log(Name) - Dim child As XmlNode=node.Children.Get(0) - If child.Name=Name Then - node=node.Children.Get(0) - End If - End Try + Dim sb As StringBuilder + sb.Initialize + sb.Append("<").Append(Name).Append(">") + sb.append(xml) + sb.Append("") + node=parser.Parse(sb.ToString) + 'Log("-------") + 'Log(sb.ToString) + 'Log(node.Name) + 'Log(Name) + Dim child As XmlNode=node.Children.Get(0) + If child.Name=Name Then + node=node.Children.Get(0) + End If Children=node.Children End Sub Public Sub setinnerText(s As String) - If Children.Size=1 Then - Dim node As XmlNode=Children.Get(0) - If node.Name="text" Then - node.Text=s - Return - End If - End If + 'If XMLUtils.XmlNodeContainsOnlyText(Me) Then + ' Children.Clear + ' s=XMLUtils.DiscloseTagText(s,False) + ' Children.Add(CreateTextNode(s)) + ' Return + 'End If Try setinnerXML(XMLUtils.TextToXML(s)) Catch @@ -125,11 +118,8 @@ Sub CreateTextNode (s As String) As XmlNode End Sub Public Sub getinnerText As String - If Children.Size=1 Then - Dim node As XmlNode=Children.Get(0) - If node.Name="text" Then - Return node.Text - End If - End If + 'If XMLUtils.XmlNodeContainsOnlyText(Me) Then + ' Return XMLUtils.EncloseTagText(XMLUtils.XmlNodeText(Me),False) + 'End If Return XMLUtils.XMLToText(getinnerXML) End Sub \ No newline at end of file