EnableExplicit

CompilerIf #ctSSLayer_CompiledFeature_ReadTags
  Procedure.s TrimA(xString.s)
    Define.l StartPos = 1
    Define.l CharCount = Len(xString)
    Define.l xLong1

    While CharCount
      If Asc(Mid(xString, CharCount, 1)) < 33
        CharCount - 1
        Else
        Break
        EndIf
      Wend

    While CharCount
      If Asc(Mid(xString, StartPos, 1)) < 33
        CharCount - 1
        StartPos + 1
        Else
        Break
        EndIf
      Wend
    
    If CharCount
      For xLong1 = StartPos To StartPos + CharCount - 1
        If Asc(Mid(xString, xLong1, 1)) < 32
          PokeB(@xString + xLong1 - 1, 32)
          EndIf
        Next
      ProcedureReturn Mid(xString, StartPos, CharCount)
      EndIf
    EndProcedure

  Procedure TrimW(*ptrStartPos, *ptrCharCountWONC) ;characters (not bytes!) without nullchar(s)
    ; will once trim / fix le/be  
    ; 32 - 00 if no BigEndian, ... no swaping,,,?
    Define.l StartPos
    Define.l CharCount
    Define.l xLong1
    ;Define.l CharCountOld
  
    StartPos = PeekL(*ptrStartPos)
    CharCount = PeekL(*ptrCharCountWONC)
    ;CharCountOld = CharCount
    
  ;  ProcedureReturn
    
  ;  If CharCount
      Repeat
        ;Break
        If PeekW(StartPos) < 33
          StartPos + 2
          CharCount - 1
          If CharCount = 0
            Goto TrimW_Lbl1
            EndIf
          Else
          Break
          EndIf
        ForEver
      Repeat
        ;Break
        If PeekW(StartPos + CharCount * 2 - 2) < 33
          CharCount - 1
          If CharCount = 0
            Goto TrimW_Lbl1
            EndIf
          Else
          Break
          EndIf
        ForEver
      PokeL(*ptrStartPos, StartPos)
      For xLong1 = StartPos To StartPos + CharCount * 2 - 2 Step 2
        If PeekW(xLong1) < 32
          PokeL(xLong1, 32)
          EndIf
        Next
  TrimW_Lbl1:
      PokeL(*ptrCharCountWONC, CharCount)
      PokeW(StartPos + CharCount * 2, 0)
  ;    EndIf
    EndProcedure
  CompilerEndIf

; IDE Options = PureBasic 4.51 (Windows - x86)
; CursorPosition = 3
; Folding = -
; DisableDebugger
; CompileSourceDirectory