Fossil

Diff
Login

Differences From Artifact [ffe3dddccb]:

To Artifact [9549c2c71b]:


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
**        nul      ->   \0
**        \        ->   \\
**
** The fossilize() routine does an encoding of its input and
** returns a pointer to the encoding in space obtained from
** malloc.
*/








char *fossilize(const char *zIn, int nIn){
  int n, i, j, c;

  char *zOut;
  if( nIn<0 ) nIn = strlen(zIn);
  for(i=n=0; i<nIn; i++){
    c = zIn[i];
    if( c==0 || isspace(c) || c=='\\' ) n++;
  }
  n += nIn;
  zOut = malloc( n+1 );
  if( zOut ){
    for(i=j=0; i<nIn; i++){
      int c = zIn[i];
      if( c==0 ){
        zOut[j++] = '\\';
        zOut[j++] = '0';
      }else if( c=='\\' ){
        zOut[j++] = '\\';
        zOut[j++] = '\\';
      }else if( isspace(c) ){
        zOut[j++] = '\\';
        switch( c ){

          case '\n':  c = 'n'; break;
          case ' ':   c = 's'; break;
          case '\t':  c = 't'; break;
          case '\r':  c = 'r'; break;
          case '\v':  c = 'v'; break;
          case '\f':  c = 'f'; break;
        }

        zOut[j++] = c;
      }else{
        zOut[j++] = c;
      }
    }
    zOut[j] = 0;
  }
  return zOut;
}

/*







>
>
>
>
>
>
>
>

|
>









<
|
<
|
|
|
|
<
<
<
|
>
|
|
|
|
|
|
|
>
|
<
|
<







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
**        nul      ->   \0
**        \        ->   \\
**
** The fossilize() routine does an encoding of its input and
** returns a pointer to the encoding in space obtained from
** malloc.
*/

#ifdef __MINGW32__
int isspace(int c)
{
	return	(c==' ' || c=='\n' || c=='\r' || c=='\r' || c=='\f' || c=='\v' ) ;
}
#endif

char *fossilize(const char *zIn, int nIn){
  int n, i, j;
  char c;
  char *zOut;
  if( nIn<0 ) nIn = strlen(zIn);
  for(i=n=0; i<nIn; i++){
    c = zIn[i];
    if( c==0 || isspace(c) || c=='\\' ) n++;
  }
  n += nIn;
  zOut = malloc( n+1 );
  if( zOut ){

	  j = 0;

	  while (*zIn != '\0') {
		c = *zIn;
		if( c=='\\'  || isspace(c)) {
			zOut[j++] = '\\';



			switch( c ){
				case '\\':  c = '\\'; break;
				case '\n':  c = 'n'; break;
				case ' ':   c = 's'; break;
				case '\t':  c = 't'; break;
				case '\r':  c = 'r'; break;
				case '\v':  c = 'v'; break;
				case '\f':  c = 'f'; break;
			}
		}
		zOut[j++] = c;

	  ++zIn;

    }
    zOut[j] = 0;
  }
  return zOut;
}

/*