Fossil

Check-in [f61958b1]
Login

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

Overview
Comment:Fix various corner cases for the TH1 'string first' and 'string last' sub-commands.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f61958b183db741bec27ffffcad25acb44856bed
User & Date: mistachkin 2014-01-16 07:05:36
References
2014-01-16
22:08
Cherrypick MSVC/TH1 related fixes [42316a14e2], [354288db9c], [9dc0877d91], [fb29094a8f], [e0f22dda7b], [1aeb2726b0], [95292a13fa], [5e368e911d], [dd8d317670], and [f61958b183] from trunk. check-in: 93832bd9 user: mistachkin tags: branch-1.28
10:01
Cherrypick MSVC/TH1 related fixes [42316a14e2], [354288db9c], [9dc0877d91], [fb29094a8f], [e0f22dda7b], [1aeb2726b0], [95292a13fa], [5e368e911d], [dd8d317670], and [f61958b183] from trunk for review. check-in: 76442af7 user: mistachkin tags: branch-1.28
Context
2014-01-16
20:07
Fix use of window.getComputedStyle() function for IE8. Same fix as done in [5885241f52c6182e] for timeline. check-in: de0ae927 user: jan.nijtmans tags: trunk
10:54
Better NULL-protection against browsers which don't have "history" API check-in: 02b607a0 user: jan.nijtmans tags: tree-view-work
10:01
Cherrypick MSVC/TH1 related fixes [42316a14e2], [354288db9c], [9dc0877d91], [fb29094a8f], [e0f22dda7b], [1aeb2726b0], [95292a13fa], [5e368e911d], [dd8d317670], and [f61958b183] from trunk for review. check-in: 76442af7 user: mistachkin tags: branch-1.28
07:05
Fix various corner cases for the TH1 'string first' and 'string last' sub-commands. check-in: f61958b1 user: mistachkin tags: trunk
06:31
Fix typo in TH1 'string last' error message. check-in: dd8d3176 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/th_lang.c.

648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668



669

670
671
672
673
674

675
676
677
678
679
680
681
...
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729



730

731
732
733
734
735

736
737
738
739
740
741
742
** TH Syntax:
**
**   string first NEEDLE HAYSTACK
*/
static int string_first_command(
  Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
){
  const char *zNeedle;
  int nNeedle;
  const char *zHaystack;
  int nHaystack;
  int i;
  int iRes = -1;

  if( argc!=4 ){
    return Th_WrongNumArgs(interp, "string first needle haystack");
  }

  zNeedle = argv[2];
  nNeedle = argl[2];
  zHaystack = argv[3];



  nHaystack = argl[3];


  for(i=0; i<(nHaystack-nNeedle); i++){
    if( 0==memcmp(zNeedle, &zHaystack[i], nNeedle) ){
      iRes = i;
      break;

    }
  }

  return Th_SetResultInt(interp, iRes);
}

/*
................................................................................
** TH Syntax:
**
**   string last NEEDLE HAYSTACK
*/
static int string_last_command(
  Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
){
  const char *zNeedle;
  int nNeedle;
  const char *zHaystack;
  int nHaystack;
  int i;
  int iRes = -1;

  if( argc!=4 ){
    return Th_WrongNumArgs(interp, "string last needle haystack");
  }

  zNeedle = argv[2];
  nNeedle = argl[2];
  zHaystack = argv[3];



  nHaystack = argl[3];


  for(i=nHaystack-nNeedle-1; i>=0; i--){
    if( 0==memcmp(zNeedle, &zHaystack[i], nNeedle) ){
      iRes = i;
      break;

    }
  }

  return Th_SetResultInt(interp, iRes);
}

/*







<

<

<






<

|
>
>
>
|
>

|
|
|
|
>







 







<

<

<






<

|
>
>
>
|
>

|
|
|
|
>







648
649
650
651
652
653
654

655

656

657
658
659
660
661
662

663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
...
710
711
712
713
714
715
716

717

718

719
720
721
722
723
724

725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
** TH Syntax:
**
**   string first NEEDLE HAYSTACK
*/
static int string_first_command(
  Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
){

  int nNeedle;

  int nHaystack;

  int iRes = -1;

  if( argc!=4 ){
    return Th_WrongNumArgs(interp, "string first needle haystack");
  }


  nNeedle = argl[2];
  nHaystack = argl[3];

  if( nNeedle && nHaystack && nNeedle<=nHaystack ){
    const char *zNeedle = argv[2];
    const char *zHaystack = argv[3];
    int i;

    for(i=0; i<=(nHaystack-nNeedle); i++){
      if( 0==memcmp(zNeedle, &zHaystack[i], nNeedle) ){
        iRes = i;
        break;
      }
    }
  }

  return Th_SetResultInt(interp, iRes);
}

/*
................................................................................
** TH Syntax:
**
**   string last NEEDLE HAYSTACK
*/
static int string_last_command(
  Th_Interp *interp, void *ctx, int argc, const char **argv, int *argl
){

  int nNeedle;

  int nHaystack;

  int iRes = -1;

  if( argc!=4 ){
    return Th_WrongNumArgs(interp, "string last needle haystack");
  }


  nNeedle = argl[2];
  nHaystack = argl[3];

  if( nNeedle && nHaystack && nNeedle<=nHaystack ){
    const char *zNeedle = argv[2];
    const char *zHaystack = argv[3];
    int i;

    for(i=nHaystack-nNeedle; i>=0; i--){
      if( 0==memcmp(zNeedle, &zHaystack[i], nNeedle) ){
        iRes = i;
        break;
      }
    }
  }

  return Th_SetResultInt(interp, iRes);
}

/*

Changes to test/th1.test.

205
206
207
208
209
210
211


























































































fossil test-th-eval "set gv 1; upvar 0 gv gv2(1); unset gv; unset gv2(1)"
test th1-unset-7 {$RESULT eq {TH_ERROR: no such variable: gv2(1)}}

###############################################################################

fossil test-th-eval "set gv(1) 1; upvar 0 gv(1) gv2; unset gv(1); unset gv2"
test th1-unset-8 {$RESULT eq {TH_ERROR: no such variable: gv2}}

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
fossil test-th-eval "set gv 1; upvar 0 gv gv2(1); unset gv; unset gv2(1)"
test th1-unset-7 {$RESULT eq {TH_ERROR: no such variable: gv2(1)}}

###############################################################################

fossil test-th-eval "set gv(1) 1; upvar 0 gv(1) gv2; unset gv(1); unset gv2"
test th1-unset-8 {$RESULT eq {TH_ERROR: no such variable: gv2}}

###############################################################################

fossil test-th-eval "string first {} {}"
test th1-string-first-1 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string first {} {a}"
test th1-string-first-2 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string first {a} {}"
test th1-string-first-3 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string first {a} {a}"
test th1-string-first-4 {$RESULT eq {0}}

###############################################################################

fossil test-th-eval "string first {a} {aa}"
test th1-string-first-5 {$RESULT eq {0}}

###############################################################################

fossil test-th-eval "string first {aa} {a}"
test th1-string-first-6 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string first {ab} {abc}"
test th1-string-first-7 {$RESULT eq {0}}

###############################################################################

fossil test-th-eval "string first {bc} {abc}"
test th1-string-first-8 {$RESULT eq {1}}

###############################################################################

fossil test-th-eval "string first {AB} {abc}"
test th1-string-first-9 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string last {} {}"
test th1-string-last-1 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string last {} {a}"
test th1-string-last-2 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string last {a} {}"
test th1-string-last-3 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string last {a} {a}"
test th1-string-last-4 {$RESULT eq {0}}

###############################################################################

fossil test-th-eval "string last {a} {aa}"
test th1-string-last-5 {$RESULT eq {1}}

###############################################################################

fossil test-th-eval "string last {aa} {a}"
test th1-string-last-6 {$RESULT eq {-1}}

###############################################################################

fossil test-th-eval "string last {ab} {abc}"
test th1-string-last-7 {$RESULT eq {0}}

###############################################################################

fossil test-th-eval "string last {bc} {abc}"
test th1-string-last-8 {$RESULT eq {1}}

###############################################################################

fossil test-th-eval "string last {AB} {abc}"
test th1-string-last-9 {$RESULT eq {-1}}