Fossil

Diff
Login

Differences From Artifact [5f672a8d7e]:

To Artifact [798989c30c]:


2484
2485
2486
2487
2488
2489
2490
2491
2492


2493
2494

2495
2496

2497
2498

2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523



































2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540



2541
2542
2543
2544
2545

2546
2547
2548
2549
2550
2551
2552
2484
2485
2486
2487
2488
2489
2490


2491
2492


2493


2494
2495

2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508

2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570


2571
2572
2573

2574



2575
2576
2577
2578
2579
2580
2581
2582







-
-
+
+
-
-
+
-
-
+

-
+












-












+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
-
+
+
+
-

-
-
-
+







    }
  }
  *pResult = sign<0 ? -v1 : v1;
  return z - zBegin;
}

/*
** Try to convert the string passed as arguments (z, n) to an integer.
** If successful, store the result in *piOut and return TH_OK. 
** Attempts to convert (zArg,nArg) to an integer. On success *piOut is
** assigned to its value and TH_OK is returned, else piOut is not
**
** If the string cannot be converted to an integer, return TH_ERROR. 
** modified and TH_ERROR is returned. Conversion errors are considered
** If the interp argument is not NULL, leave an error message in the 
** interpreter result too.
** non-fatal here, so interp's error state is not set.
*/
int Th_ToInt(Th_Interp *interp, const char *z, int n, int *piOut){
int Th_TryInt(Th_Interp *interp, const char *z, int n, int *piOut){
  int i = 0;
  int iOut = 0;

  if( n<0 ){
    n = th_strlen(z);
  }

  if( n>0 && (z[0]=='-' || z[0]=='+') ){
    i = 1;
  }
  for(; i<n; i++){
    if( !th_isdigit(z[i]) ){
      Th_ErrorMessage(interp, "expected integer, got: \"", z, n);
      return TH_ERROR;
    }
    iOut = iOut * 10 + (z[i] - 48);
  }

  if( n>0 && z[0]=='-' ){
    iOut *= -1;
  }

  *piOut = iOut;
  return TH_OK;
}

/*
** Try to convert the string passed as arguments (z, n) to an integer.
** If successful, store the result in *piOut and return TH_OK. 
**
** If the string cannot be converted to an integer, return TH_ERROR. 
** If the interp argument is not NULL, leave an error message in the 
** interpreter result too.
*/
int Th_ToInt(Th_Interp *interp, const char *z, int n, int *piOut){
  const int rc = Th_TryInt(interp, z, n, piOut);
  if( TH_OK != rc ){
    Th_ErrorMessage(interp, "expected integer, got: \"", z, n);
  }
  return rc;
}


/*
** Functionally/semantically identical to Th_TryInt() but works on
** doubles.
*/
int Th_TryDouble(
  Th_Interp *interp, 
  const char *z, 
  int n, 
  double *pfOut
){
  if( !sqlite3IsNumber((const char *)z, 0) ){
    return TH_ERROR;
  }else{
    sqlite3AtoF((const char *)z, pfOut);
    return TH_OK;
  }
}

/*
** Try to convert the string passed as arguments (z, n) to a double.
** If successful, store the result in *pfOut and return TH_OK. 
**
** If the string cannot be converted to a double, return TH_ERROR. 
** If the interp argument is not NULL, leave an error message in the 
** interpreter result too.
*/
int Th_ToDouble(
  Th_Interp *interp, 
  const char *z, 
  int n, 
  double *pfOut
){
  if( !sqlite3IsNumber((const char *)z, 0) ){
    Th_ErrorMessage(interp, "expected number, got: \"", z, n);
  const int rc = Th_TryDouble(interp, z, n, pfOut);
  if( TH_OK != rc ){
      Th_ErrorMessage(interp, "expected number, got: \"", z, n);
    return TH_ERROR;
  }

  sqlite3AtoF((const char *)z, pfOut);
  return TH_OK;
  return rc;
}

/*
** Set the result of the interpreter to the th1 representation of
** the integer iVal and return TH_OK.
*/
int Th_SetResultInt(Th_Interp *interp, int iVal){