Fossil

Check-in [b28ae72e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the [string trimleft] and [string trimright] commands to TH1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ticket-enhancements
Files: files | file ages | folders
SHA1: b28ae72e846c1951536f37e773bec5ec541c83f3
User & Date: drh 2012-11-23 21:45:46
Context
2012-11-23
22:29
New and improved default ticket setup. check-in: 340040a8 user: drh tags: ticket-enhancements
21:45
Add the [string trimleft] and [string trimright] commands to TH1. check-in: b28ae72e user: drh tags: ticket-enhancements
18:32
No - render non-check-in timeline comments as wiki, since that is needed to resolve hyperlinks. check-in: 5139ad6e user: drh tags: ticket-enhancements
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th_lang.c.

817
818
819
820
821
822
823


824
825
826
827
828
829
830
831
832
833
834
835

836


837

838
839
840
841
842
843
844
...
917
918
919
920
921
922
923
924


925
926
927
928
929
930
931
  return TH_OK;
}

/*
** TH Syntax:
**
**   string trim STRING


*/
static int string_trim_command(
  Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
){
  int n;
  const char *z;

  if( argc!=3 ){
    return Th_WrongNumArgs(interp, "string trim string");
  }
  z = argv[2];
  n = argl[2];

  while( n && th_isspace(z[0]) ){ z++; n--; }


  while( n && th_isspace(z[n-1]) ){ n--; }

  Th_SetResult(interp, z, n);
  return TH_OK;
}

/*
** TH Syntax:
**
................................................................................
    { "compare", string_compare_command },
    { "first",   string_first_command },
    { "is",      string_is_command },
    { "last",    string_last_command },
    { "length",  string_length_command },
    { "range",   string_range_command },
    { "repeat",  string_repeat_command },
    { "trim",    string_trim_command },


    { 0, 0 }
  };
  return Th_CallSubCommand(interp, ctx, argc, argv, argl, aSub);
}

/*
** TH Syntax:







>
>












>
|
>
>
|
>







 







|
>
>







817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
...
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
  return TH_OK;
}

/*
** TH Syntax:
**
**   string trim STRING
**   string trimleft STRING
**   string trimright STRING
*/
static int string_trim_command(
  Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
){
  int n;
  const char *z;

  if( argc!=3 ){
    return Th_WrongNumArgs(interp, "string trim string");
  }
  z = argv[2];
  n = argl[2];
  if( argl[1]<5 || argv[1][4]=='l' ){
    while( n && th_isspace(z[0]) ){ z++; n--; }
  }
  if( argl[1]<5 || argv[1][4]=='r' ){
    while( n && th_isspace(z[n-1]) ){ n--; }
  }
  Th_SetResult(interp, z, n);
  return TH_OK;
}

/*
** TH Syntax:
**
................................................................................
    { "compare", string_compare_command },
    { "first",   string_first_command },
    { "is",      string_is_command },
    { "last",    string_last_command },
    { "length",  string_length_command },
    { "range",   string_range_command },
    { "repeat",  string_repeat_command },
    { "trim",      string_trim_command },
    { "trimleft",  string_trim_command },
    { "trimright", string_trim_command },
    { 0, 0 }
  };
  return Th_CallSubCommand(interp, ctx, argc, argv, argl, aSub);
}

/*
** TH Syntax: