#preParse_v00.py from getSub import getSub from getSub_v00 import getSub_v00 from replSub import replSub from replSub_v00 import replSub_v00 def preParse_v00(parm): #By D@CC #On 2023LDec01 #Purpose: to find pairs of ' or " # and replace each space (or spaces) in # each pair with &20 #parm1: cli str to preParse #Eg: any"any any"any"any any"any #Returns:any"any&20any"any"any&20any"any #Status: no fails by Test_preParse() #TestFile: Test_preParse_File.txt #print("at 35 parm1:"+parm1) parm1=parm #so we can change parm1 result=parm1 isAnyDQ=True if parm1.find('"')<0: isAnyDQ=False isAnySQ=True if parm1.find("'")<0: isAnySQ=False if isAnyDQ and isAnySQ: return parm1 if (not isAnyDQ) and (not isAnySQ): return parm1 if isAnyDQ or isAnySQ: for qStr in ('"',"'"): # search for both DQ and SQ q=qStr qCol= 0 cntQ =-1 #print("at 49 parm1:"+parm1) while qCol>-1 : #find next col containing q qCol =parm1.find(q,qCol+1) #count it (them) cntQ+=1 #print("55 qCol:",qCol) #while end #print("cntQ:",cntQ) modQ=cntQ%2 #print("modQ:",modQ) if modQ==1 : print("p 61: Warning:found odd number of ' or " +'"');return parm1 else: #rescan to process each pair of q's qCol=0 cntQ=0 cntPair=1 while qCol>-1: #print("p 67 check parm1:"+parm1) qCol =parm1.find(q,qCol+1) if qCol==-1: #print("next qCol:",qCol) break #done else: #print("next qCol:",qCol) pass #if end cntQ+=1 #print("77 before test cntQ,2*cntPair:",cntQ,2*cntPair) if cntQ==2*cntPair: #print("78 check need to process Pair:",cntPair) #process this pair #q1=qCol q2=qCol #print("84 q1,q2:",q1,q2) oldSub=getSub(parm1,q1,q2) # if oldSub needs spaces replaced if oldSub.find(" ")>-1: #print("p 88 replacing spaces between pair") newSub=oldSub.replace(" ","&20") parm1=replSub(parm1,q1,q2,newSub) #print("p 91 new parm1:"+parm1) #subStr=subStr.replace(" ","&20") #parm1 has changed, so restart qCol=0 cntQ=0 cntPair=1 #print("qCol:",qCol) else: #print("p 98 process next pair") cntPair+=1 #if end else: q1=qCol #if end #while end #for end result=parm1 #if end # must replace each space with "&20" #if end return result #def end #/preParse_v00.py