Skip to content

Commit

Permalink
do not check if XmlNode contains only text when updating its content
Browse files Browse the repository at this point in the history
  • Loading branch information
xulihang committed Sep 1, 2020
1 parent aff9db8 commit cab64f6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 66 deletions.
48 changes: 24 additions & 24 deletions BasicCAT/BasicCAT.b4j
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions BasicCAT/BasicCAT.b4j.meta
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions BasicCAT/Utils.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions BasicCAT/XMLUtils.bas
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,13 @@ Public Sub EncloseTagText(s As String,XMLEscaped As Boolean) As String
End Sub

'`&lt;g id="1"&gt;` -> &lt;g id="1"&gt;
Public Sub DiscloseTagText(s As String) As String
Return Regex.Replace("`(&lt;.*?&gt;)`",s,"$1")
Public Sub DiscloseTagText(s As String,escaped As Boolean) As String
If escaped Then
Return Regex.Replace("`(&lt;.*?&gt;)`",s,"$1")
Else
Return Regex.Replace("`(<.*?>)`",s,"$1")
End If

End Sub

Sub XMLToText(xml As String) As String
Expand All @@ -426,7 +431,7 @@ Sub TextToXML(s As String) As String
'escape: <g1>&</g1>-><g1>&amp;</g1> 'xliff tags not escaped except they are enclosed with ``
Dim Xml As String=HandleXMLEntities(s,True)
'disclose tags: `&lt;g&gt;` -> &lt;g&gt;
Xml=DiscloseTagText(Xml)
Xml=DiscloseTagText(Xml,True)
Return Xml
End Sub

Expand Down
56 changes: 23 additions & 33 deletions BasicCAT/XmlNode.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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("</").Append(Name).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("</").Append(Name).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
Expand All @@ -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

0 comments on commit cab64f6

Please sign in to comment.