~ubuntu-branches/ubuntu/wily/unrar-nonfree/wily-proposed

« back to all changes in this revision

Viewing changes to strfn.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2012-02-14 22:39:32 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20120214223932-wi7jd1zvqed61bw2
Tags: 1:4.1.4-1
* New upstream release
* Updated Watch file
* Added build-indep and build-arch to rules file

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
}
13
13
 
14
14
 
 
15
 
 
16
 
15
17
char *IntNameToExt(const char *Name)
16
18
{
17
19
  static char OutName[NM];
22
24
 
23
25
void ExtToInt(const char *Src,char *Dest)
24
26
{
25
 
#if defined(_WIN_ALL)
 
27
#ifdef _WIN_ALL
26
28
  CharToOemA(Src,Dest);
27
29
#else
28
30
  if (Dest!=Src)
33
35
 
34
36
void IntToExt(const char *Src,char *Dest)
35
37
{
36
 
#if defined(_WIN_ALL)
 
38
#ifdef _WIN_ALL
37
39
  OemToCharA(Src,Dest);
38
40
#else
39
41
  if (Dest!=Src)
172
174
 
173
175
 
174
176
// We do not want to cast every signed char to unsigned when passing to
175
 
// isspace, so we implement the replacement. Shall work for Unicode too.
 
177
// isalpha, so we implement the replacement. Shall work for Unicode too.
176
178
// If chars are signed, conversion from char to int could generate negative
177
179
// values, resulting in undefined behavior in standard function.
178
180
bool IsAlpha(int ch)
183
185
 
184
186
 
185
187
 
 
188
#ifndef SFX_MODULE
 
189
uint GetDigits(uint Number)
 
190
{
 
191
  uint Digits=1;
 
192
  while (Number>=10)
 
193
  {
 
194
    Number/=10;
 
195
    Digits++;
 
196
  }
 
197
  return(Digits);
 
198
}
 
199
#endif
 
200
 
186
201
 
187
202
bool LowAscii(const char *Str)
188
203
{
254
269
}
255
270
 
256
271
 
 
272
// Safe strncat: resulting dest length cannot exceed maxlen and dest 
 
273
// is always zero terminated. Note that 'maxlen' parameter defines the entire
 
274
// dest buffer size and is not compatible with standard strncat.
 
275
char* strncatz(char* dest, const char* src, size_t maxlen)
 
276
{
 
277
  size_t Length = strlen(dest);
 
278
  if (Length + 1 < maxlen)
 
279
    strncat(dest, src, maxlen - Length - 1);
 
280
  return dest;
 
281
}
 
282
 
 
283
 
 
284
// Safe wcsncat: resulting dest length cannot exceed maxlen and dest 
 
285
// is always zero terminated. Note that 'maxlen' parameter defines the entire
 
286
// dest buffer size and is not compatible with standard wcsncat.
 
287
wchar* wcsncatz(wchar* dest, const wchar* src, size_t maxlen)
 
288
{
 
289
  size_t Length = wcslen(dest);
 
290
  if (Length + 1 < maxlen)
 
291
    wcsncat(dest, src, maxlen - Length - 1);
 
292
  return dest;
 
293
}
 
294
 
 
295
 
257
296
void itoa(int64 n,char *Str)
258
297
{
259
298
  char NumStr[50];
272
311
 
273
312
 
274
313
 
275
 
int64 atoil(char *Str)
 
314
int64 atoil(const char *Str)
276
315
{
277
316
  int64 n=0;
278
317
  while (*Str>='0' && *Str<='9')
301
340
}
302
341
 
303
342
 
304
 
int64 atoil(wchar *Str)
 
343
int64 atoil(const wchar *Str)
305
344
{
306
345
  int64 n=0;
307
346
  while (*Str>='0' && *Str<='9')
325
364
  Str[MaxLength-1]=0;
326
365
  return(Str);
327
366
}
 
367
 
 
368
 
 
369
#ifdef _WIN_ALL
 
370
// Parse string containing parameters separated with spaces.
 
371
// Support quote marks. Param can be NULL to return the pointer to next
 
372
// parameter, which can be used to estimate the buffer size for Param.
 
373
const wchar* GetCmdParam(const wchar *CmdLine,wchar *Param,size_t MaxSize)
 
374
{
 
375
  while (IsSpace(*CmdLine))
 
376
    CmdLine++;
 
377
  if (*CmdLine==0)
 
378
    return NULL;
 
379
 
 
380
  size_t ParamSize=0;
 
381
  bool Quote=false;
 
382
  while (*CmdLine!=0 && (Quote || !IsSpace(*CmdLine)))
 
383
  {
 
384
    if (*CmdLine=='\"')
 
385
    {
 
386
      if (CmdLine[1]=='\"')
 
387
      {
 
388
        // Insert the quote character instead of two adjoining quote characters.
 
389
        if (Param!=NULL && ParamSize<MaxSize-1)
 
390
          Param[ParamSize++]='\"';
 
391
        CmdLine++;
 
392
      }
 
393
      else
 
394
        Quote=!Quote;
 
395
    }
 
396
    else
 
397
      if (Param!=NULL && ParamSize<MaxSize-1)
 
398
        Param[ParamSize++]=*CmdLine;
 
399
    CmdLine++;
 
400
  }
 
401
  if (Param!=NULL)
 
402
    Param[ParamSize]=0;
 
403
  return CmdLine;
 
404
}
 
405
#endif