
; Territory_TransformString SWI for english territory

; Entry: R1 = destination string buffer
;        R2 = source string
;        R3 = length of destination string buffer
;
; Exit:  R0 = The length of the transformed string (not including the
;             terminating null character). If the returned value is >= R3 on
;             entry the contents of the buffer pointed to by R1 are
;             indeterminate.
;
;        The Territory_TransformString SWI transforms the string pointed to
;        by R2 and places the resulting string into the buffer pointed to by
;        R1. The transformation is such that if a byte by byte comparison is
;        applied to two transformed strings the strings will compare less
;        than, equal to or greater than as though Territory_Collate had been
;        appled to the original strings. No more than R3 bytes are placed in
;        the buffer pointed to by R1 including a terminating null character.
;        If R3 is 0 R1 may be a null pointer. If copying takes place between
;        strings that overlap the behaviour is undefined.
;
; OSmith 30-Apr-92 Added two instructions to make code actually transform
; the string rather than just copying it!

TransformString
        Entry   "r1-r4"
        SUB     r12, r2, #1
01      LDRB    r0, [r12, #1]!  ; r0 = strlen(r2)
        CMP     r0, #0
        BNE     %B01
        SUB     r0, r12, r2
        ADRL    r4, SortValueTable
02      SUBS    r3, r3, #1      ; for (; r3!=0; r3--)
        EXITS   CC
        LDRB    r12, [r2], #1   ;     if ((*r1++ = *r2++) == 0) break;
        LDRB    r12, [r4, r12]  ; OSS Read sort value table entry
        STRB    r12, [r1], #1
        CMP     r12, #0
        BNE     %B02
        EXITS                   ; return r0

        LNK     Sources.tail
