如何减少livecode的时间

时间:2015-04-14 09:23:12

标签: livecode

我需要保留一些文本,所以我从滚动字段中获取该文本并在编辑之前存储在数组和变量中,在编辑之后,我恢复了那些地方的文本。我正在使用此代码进行此过程,它工作正常,但它花了很多时间。如何缩短时间?

 command Store
       global ELine,m,EELine,myEELength,myELength,EQLine,myEQLength,EALine,myEALength,ESLine,ESuLine,myESLength,myESuLength,TSLine,myTSLength,stsLine,sta,stab,Tta
       global wPreserve,woPreserve,endwPreserve,cnt
       put the text of field "MytextField" into woPreserve 
       put the number of lines of woPreserve into cnt
       --answer cnt 
       repeat with x = 1 to the number of lines of woPreserve
          if line x of woPreserve contains "begin{thebibliography}" then
             put line x to cnt  in woPreserve into endwPreserve
             delete line x+1 to cnt in field "MytextField"
             --answer endwPreserve
          end if
       end repeat
       repeat with x = 1 to the number of lines of woPreserve
          if line x of woPreserve contains "begin{document}" then 
             put line 1 to x-1 in woPreserve into wPreserve
             delete line 1 to x-1 in field "MytextField"
             --answer wPreserve
          end if
       end repeat


       set the caseSensitive to true

       put "" into ELine
       replace "\$" with "{\XXdollarXX}" in field "MytextField"
       put the text of field "MytextField" into Tvar
       --put replaceText(Tvar,"[a-z,A-Z]\$"
       put replaceText(Tvar,"\n","^EOL") into field "MytextField"
       put the text of field "MytextField" into Tvar
       put the number of paragraphs in Tvar into ppara

       repeat with p = 0 to ppara
          put paragraph p of Tvar into q
          --put replaceText(q,"\s\n","") after aa
          put replaceText(q,"\n","") after aa
       end repeat

       --put aa into field "MytextField"

       replace "^EOL\begin{Seqnarray}" with cr & "\begin{Seqnarray}" in field "MytextField"
       replace "\end{Seqnarray}^EOL" with "\end{Seqnarray}" & cr in field "MytextField"
       replace "^EOL\begin{subequation}" with cr & "\begin{subequation}" in field "MytextField"
       replace "\end{subequation}^EOL" with "\end{subequation}" & cr in field "MytextField"
       replace "^EOL\begin{equation}" with cr & "\begin{equation}" in field "MytextField"
       replace "\end{equation}^EOL" with "\end{equation}" & cr in field "MytextField"
       replace "^EOL\begin{eqnarray}" with cr & "\begin{eqnarray}" in field "MytextField"
       replace "\end{eqnarray}^EOL" with "\end{eqnarray}" & cr in field "MytextField"
       replace "^EOL\begin{align}" with cr & "\begin{align}" in field "MytextField"
       replace "\end{align}^EOL" with "\end{align}" & cr in field "MytextField"
       replace "^EOL\begin{Table}" with cr & "\begin{Table}" in field "MytextField"
       replace "\end{Table}^EOL" with "\end{Table}" & cr in field "MytextField"
       replace "^EOL\begin{table}" with cr & "\begin{table}" in field "MytextField"
       replace "\end{table}^EOL" with "\end{table}" & cr in field "MytextField"

       --replace "\begin{Seqnarray}" with cr & "\begin{Seqnarray}" in field "MytextField"
       replace "\end{Seqnarray}" with "\end{Seqnarray}" & cr  in field "MytextField"
       --replace "^EOL\begin{subequation}" with cr & "\begin{subequation}" in field "MytextField"
       replace "\end{subequation}" with "\end{subequation}" & cr in field "MytextField"
       --replace "^EOL\begin{equation}" with cr & "\begin{equation}" in field "MytextField"
       replace "\end{equation}" with "\end{equation}" & cr in field "MytextField"
       --replace "^EOL\begin{eqnarray}" with cr & "\begin{eqnarray}" in field "MytextField"
       replace "\end{eqnarray}" with "\end{eqnarray}" & cr in field "MytextField"
       --replace "^EOL\begin{align}" with cr & "\begin{align}" in field "MytextField"
       replace "\end{align}" with "\end{align}"  in field "MytextField"






       --put the text of field  "MytextField" into aa
       put 0 into k
       put 0 into z
       put 0 into n
       put 0 into j
       put 0 into l
       put 0 into Ta
       put 0 into stab

       put the text of field  "MytextField" into aa
       repeat for each lines ET in aa
          if ET contains "\begin{subequation}" then
             add 1 to k
             put "-----SubDisplayEquation-----" & k into es
             replace ET with es in field "MytextField"
             put  ET & cr after ESLine
          end if     

          if ET contains "\begin{Seqnarray}" then
             add 1 to z
             put "-----SDisplayEquation-----" & z into eSu
             replace ET with eSu in field "MytextField"
             put  ET & cr after ESuLine
          end if     

          if ET contains "\begin{equation}" then
             add 1 to n
             put "-----DisplayEquation-----" & n into eo
             replace ET with eo in field "MytextField"
             put  ET & cr after EELine
          end if     
          if ET contains "\begin{eqnarray}" then
             add 1 to j
             put "-----EqnarryDisplayEquation-----" & j into er
             replace ET with er in field "MytextField"
             put  ET & cr after EQLine
          end if     

          if ET contains "\begin{align}" then
             add 1 to l
             put "-----AlignDisplayEquation-----" & l into ea
             replace ET with ea in field "MytextField"
             put  ET & cr after EALine
          end if     

          if ET contains "\begin{Table}" then
             add 1 to Ta
             put "-----Table-----" & Ta into Tta
             replace ET with Tta in field "MytextField"
             put  ET & cr after TSLine
          end if     

          if ET contains "\begin{table}" then
             add 1 to stab
             put "-----_table_-----" & stab into sta
             replace ET with sta in field "MytextField"
             put  ET & cr after stsLine
          end if    

       end repeat

       put the text of field "MytextField" into ss
       put "" into yy
       put 0 into tmp

       repeat with i = 1 to the number of chars in ss
          if char i of ss contains "$" then
             add 1 to tmp
             if tmp = 1 then
                put "^SOE" & CR & char i of ss after yy
             else
                put char i of ss & CR & "^EOE" after yy
                put 0 into tmp
             end if
          else
             put char i of ss after yy
          end if
       end repeat
       put yy into the field "MytextField"

       put 0 into m
       repeat for each lines iT in yy
          if iT contains "$" then
             add 1 to m
             put "---In_Line_Equation---" & m into so
             replace IT with so in field "MytextField"
             put  iT & cr after ELine
          end if     

       end repeat
       --answer ELine
       put 0 into m

       put the text of field "MytextField" into SSEE

       put replaceText(SSEE, "\^SOE\n","") into SSEE
       put replaceText(SSEE, "\n\^EOE","") into SSEE
       put replaceText(SSEE, "\^EOL",cr) into SSEE
       --answer SSEE
       put SSEE into field "MytextField"

    end Store

    command Restore
       global ELine,m,EELine,myEELength,myELength,EQLine,myEQLength,EALine,myEALength,ESLine,ESuLine,myESLength,myESuLength,TSLine,myTSLength,stsLine,sta,stab,mystsLength
    global wPreserve,x,woPreserve,endwPreserve,cnt

       put cr into line 0 of field "MytextField"
       put wPreserve into line 0 of field "MytextField"
       put "" into wPreserve
       put cr into last line of field "MytextField"
       put endwPreserve into last line of field "MytextField"
       put "" into endwPreserve


       put the number of lines of ESLine into myESLength
       split ESLine by cr
       put myESLength into k
       repeat with i = myESLength down to 1
          put "-----SubDisplayEquation-----" & k into es
          replace es with ESLine[i] in field "MytextField"
          subtract 1 from k
       end repeat

       put the number of lines of ESuLine into myESuLength
       split ESuLine by cr
       put myESuLength into z
       repeat with i = myESuLength down to 1
          put "-----SDisplayEquation-----" & z into eSu
          replace eSu with ESuLine[i] in field "MytextField"
          subtract 1 from z
       end repeat


       put the number of lines of EELine into myEELength
       split EELine by cr
       put myEELength into n
       repeat with i = myEELength down to 1
          put "-----DisplayEquation-----" & n into eo
          replace eo with EELine[i] in field "MytextField"
          subtract 1 from n
       end repeat


       put the number of lines of EQLine into myEQLength
       split EQLine by cr
       put myEQLength into j
       repeat with i = myEQLength down to 1
          put "-----EqnarryDisplayEquation-----" & j into er
          replace er with EQLine[i] in field "MytextField"
          subtract 1 from j
       end repeat


       put the number of lines of EALine into myEALength
       split EALine by cr
       put myEALength into l
       repeat with i = myEALength down to 1
          put "-----AlignDisplayEquation-----" & l into ea
          replace ea with EALine[i] in field "MytextField"
          subtract 1 from l
       end repeat


       put the number of lines of TSLine into myTSLength
       split TSLine by cr
       put myTSLength into Ts
       repeat with i = myTSLength down to 1
          put "-----Table-----" & Ts into Tta
          replace Tta with TSLine[i] in field "MytextField"
          subtract 1 from Ts
       end repeat


       put the number of lines of stsLine into mystsLength
       split stsLine by cr
       put mystsLength into stab
       repeat with i = mystsLength down to 1
          put "-----_table_-----" & stab into sta
          replace sta with stsLine[i] in field "MytextField"
          subtract 1 from stab
       end repeat

       put the number of lines of ELine into myELength
       split ELine by cr
       put myELength into m
       repeat with i =  myELength down to 1
          put "---In_Line_Equation---" & m into so
          replace so with ELine[i] in field "MytextField"
          subtract 1 from m
       end repeat

       replace "^EOL" with cr in field "MytextField"
       replace "\$" with "{\XXdollarXX}" in field "MytextField"
    end Restore

有没有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:3)

看起来你正在一个字段中进行所有文本替换。您应该首先将文本内容放入变量中,然后在那里替换所有内容,然后将变量的内容放回到字段中。