SCCVEGU0 ;ALB/JRP - UTILS FOR ENCNTR CNVRSN GLBL ESTMTR;11-JAN-1996
;;5.3;Scheduling;**211**;Aug 13, 1993
INSERT(INSTR,OUTSTR,COLUMN,LENGTH) ;INSERT A STRING INTO ANOTHER
;INPUT : INSTR - String to insert
; OUTSTR - String to insert into
; COLUMN - Where to begin insertion (defaults to end of OUTSTR)
; LENGTH - Number of characters to clear from OUTSTR
; (defaults to length of INSTR)
;OUTPUT : s - INSTR will be placed into OUTSTR starting at COLUMN
; using LENGTH characters
; "" - Error (bad input)
;
;NOTE : This module is based on $$SETSTR^VALM1
;
N STRING
Q:'$D(INSTR)!'$D(OUTSTR) ""
I '$G(COLUMN) N COLUMN S COLUMN=$L(OUTSTR)+1
I '$G(LENGTH) N LENGTH S LENGTH=$L(INSTR)
S INSTR=$S($L(INSTR)<LENGTH:INSTR_$J("",LENGTH-$L(INSTR)),1:INSTR)
S $E(OUTSTR,COLUMN,COLUMN+LENGTH-1)=INSTR
Q OUTSTR
;
CENTER(CNTRSTR,MARGIN) ;CENTER A STRING
;INPUT : CNTRSTR - String to center
; MARGIN - Margin width to center within (defaults to 80)
;OUTPUT : s - INSTR will be centered in a margin width of MARGIN
; "" - Error (bad input)
;NOTES : A margin width of 80 will be used when MARGIN<1
; : CNTRSTR will be returned when $L(CNTRSTR)>MARGIN
;
N STRING,FROM
;Check input
Q:($G(CNTRSTR)="") ""
I $G(MARGIN)<1 N MARGIN S MARGIN=80
Q:($L(CNTRSTR)>MARGIN) CNTRSTR
S STRING="",$P(STRING," ",MARGIN+1)="",FROM=(MARGIN\2)-($L(CNTRSTR)\2)+1
S $E(STRING,FROM,FROM+$L(CNTRSTR)-1)=CNTRSTR
Q STRING
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSCCVEGU0 1541 printed Nov 22, 2024@17:48:51 Page 2
SCCVEGU0 ;ALB/JRP - UTILS FOR ENCNTR CNVRSN GLBL ESTMTR;11-JAN-1996
+1 ;;5.3;Scheduling;**211**;Aug 13, 1993
INSERT(INSTR,OUTSTR,COLUMN,LENGTH) ;INSERT A STRING INTO ANOTHER
+1 ;INPUT : INSTR - String to insert
+2 ; OUTSTR - String to insert into
+3 ; COLUMN - Where to begin insertion (defaults to end of OUTSTR)
+4 ; LENGTH - Number of characters to clear from OUTSTR
+5 ; (defaults to length of INSTR)
+6 ;OUTPUT : s - INSTR will be placed into OUTSTR starting at COLUMN
+7 ; using LENGTH characters
+8 ; "" - Error (bad input)
+9 ;
+10 ;NOTE : This module is based on $$SETSTR^VALM1
+11 ;
+12 NEW STRING
+13 if '$DATA(INSTR)!'$DATA(OUTSTR)
QUIT ""
+14 IF '$GET(COLUMN)
NEW COLUMN
SET COLUMN=$LENGTH(OUTSTR)+1
+15 IF '$GET(LENGTH)
NEW LENGTH
SET LENGTH=$LENGTH(INSTR)
+16 SET INSTR=$SELECT($LENGTH(INSTR)<LENGTH:INSTR_$JUSTIFY("",LENGTH-$LENGTH(INSTR)),1:INSTR)
+17 SET $EXTRACT(OUTSTR,COLUMN,COLUMN+LENGTH-1)=INSTR
+18 QUIT OUTSTR
+19 ;
CENTER(CNTRSTR,MARGIN) ;CENTER A STRING
+1 ;INPUT : CNTRSTR - String to center
+2 ; MARGIN - Margin width to center within (defaults to 80)
+3 ;OUTPUT : s - INSTR will be centered in a margin width of MARGIN
+4 ; "" - Error (bad input)
+5 ;NOTES : A margin width of 80 will be used when MARGIN<1
+6 ; : CNTRSTR will be returned when $L(CNTRSTR)>MARGIN
+7 ;
+8 NEW STRING,FROM
+9 ;Check input
+10 if ($GET(CNTRSTR)="")
QUIT ""
+11 IF $GET(MARGIN)<1
NEW MARGIN
SET MARGIN=80
+12 if ($LENGTH(CNTRSTR)>MARGIN)
QUIT CNTRSTR
+13 SET STRING=""
SET $PIECE(STRING," ",MARGIN+1)=""
SET FROM=(MARGIN\2)-($LENGTH(CNTRSTR)\2)+1
+14 SET $EXTRACT(STRING,FROM,FROM+$LENGTH(CNTRSTR)-1)=CNTRSTR
+15 QUIT STRING
+16 ;