Changeset 1501 for qrda/C0Q/trunk/p/C0QUTIL.m
- Timestamp:
- Aug 2, 2012, 8:59:21 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
qrda/C0Q/trunk/p/C0QUTIL.m
r1438 r1501 1 C0QUTIL ;JJOH/ZAG/GPL - Utilities for C0Q Package ; 9/2/11 4:30pm2 ;;1.0;C0Q;;May 21, 2012;Build 431 C0QUTIL ;JJOH/ZAG/GPL - Utilities for C0Q Package ; 7/31/12 7:42am 2 ;;1.0;C0Q;;May 21, 2012;Build 63 3 3 ; 4 4 ;2011 Licensed under the terms of the GNU General Public License … … 77 77 Q Y 78 78 ; 79 ZWRITE(NAME) ; Replacement for ZWRITE ; Public Proc 80 ; Pass NAME by name as a closed reference. lvn and gvn are both supported. 81 ; : syntax is not supported (yet) 82 N L S L=$L(NAME) ; Name length 83 I $E(NAME,L-2,L)=",*)" S NAME=$E(NAME,1,L-3)_")" ; If last sub is *, remove it and close the ref 84 N ORIGLAST S ORIGLAST=$QS(NAME,$QL(NAME)) ; Get last subscript upon which we can't loop further 85 N ORIGQL S ORIGQL=$QL(NAME) ; Number of subscripts in the original name 86 I $D(@NAME)#2 W NAME,"=",$$FORMAT(@NAME),! ; Write base if it exists 87 ; $QUERY through the name. 88 ; Stop when we are out. 89 ; Stop when the last subscript of the original name isn't the same as 90 ; the last subscript of the Name. 91 F S NAME=$Q(@NAME) Q:NAME="" Q:$QS(NAME,ORIGQL)'=ORIGLAST W NAME,"=",$$FORMAT(@NAME),! 92 QUIT 93 FORMAT(V) ; Add quotes, replace control characters if necessary; Public $$ 94 ;If numeric, nothing to do. 95 ;If no encoding required, then return as quoted string. 96 ;Otherwise, return as an expression with $C()'s and strings. 97 I +V=V Q V ; If numeric, just return the value. 98 N QT S QT="""" ; Quote 99 I $F(V,QT) D ;chk if V contains any Quotes 100 . S P=0 ;position pointer into V 101 . F S P=$F(V,QT,P) Q:'P D ;find next " 102 . . S $E(V,P-1)=QT_QT ;double each " 103 . . S P=P+1 ;skip over new " 104 I $$CCC(V) D Q V ; If control character is present do this and quit 105 . S V=$$RCC(QT_V_QT) ; Replace control characters in "V" 106 . S:$E(V,1,3)="""""_" $E(V,1,3)="" ; Replace doubled up quotes at start 107 . S L=$L(V) S:$E(V,L-2,L)="_""""" $E(V,L-2,L)="" ; Replace doubled up quotes at end 108 Q QT_V_QT ; If no control charactrrs, quit with "V" 109 ; 110 CCC(S) ;test if S Contains a Control Character or $C(255); Public $$ 111 Q:S?.E1C.E 1 112 Q:$F(S,$C(255)) 1 113 Q 0 114 RCC(NA) ;Replace control chars in NA with $C( ). Returns encoded string; Public $$ 115 Q:'$$CCC(NA) NA ;No embedded ctrl chars 116 N OUT S OUT="" ;holds output name 117 N CC S CC=0 ;count ctrl chars in $C( 118 N C ;temp hold each char 119 F I=1:1:$L(NA) S C=$E(NA,I) D ;for each char C in NA 120 . I C'?1C,C'=C255 D S OUT=OUT_C Q ;not a ctrl char 121 . . I CC S OUT=OUT_")_""",CC=0 ;close up $C(... if one is open 122 . I CC D 123 . . I CC=256 S OUT=OUT_")_$C("_$A(C),CC=0 ;max args in one $C( 124 . . E S OUT=OUT_","_$A(C) ;add next ctrl char to $C( 125 . E S OUT=OUT_"""_$C("_$A(C) 126 . S CC=CC+1 127 . Q 128 Q OUT 79 129 END ;end of C0QUTIL
Note:
See TracChangeset
for help on using the changeset viewer.