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

« back to all changes in this revision

Viewing changes to unicode.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2012-02-14 22:39:32 UTC
  • mfrom: (1.2.12)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: package-import@ubuntu.com-20120214223932-80w6cf6q639kinh4
Tags: upstream-4.1.4
ImportĀ upstreamĀ versionĀ 4.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
  // We tried to return the zero terminated string if conversion is failed,
57
57
  // but it does not work well. WideCharToMultiByte returns 'failed' code
58
 
  // even if we wanted to convert only a part of string and passed DestSize
59
 
  // smaller than required for fully converted string. Such call is the valid
60
 
  // behavior in RAR code and we do not expect the empty string in this case.
 
58
  // and partially converted string even if we wanted to convert only a part
 
59
  // of string and passed DestSize smaller than required for fully converted
 
60
  // string. Such call is the valid behavior in RAR code and we do not expect
 
61
  // the empty string in this case.
61
62
 
62
63
  return(RetCode);
63
64
}
121
122
}
122
123
 
123
124
 
 
125
// SrcSize is in wide characters, not in bytes.
124
126
byte* WideToRaw(const wchar *Src,byte *Dest,size_t SrcSize)
125
127
{
126
128
  for (size_t I=0;I<SrcSize;I++,Src++)
178
180
}
179
181
 
180
182
 
181
 
void UtfToWide(const char *Src,wchar *Dest,size_t DestSize)
 
183
// Dest can be NULL if we only need to check validity of Src.
 
184
bool UtfToWide(const char *Src,wchar *Dest,size_t DestSize)
182
185
{
183
186
  long dsize=(long)DestSize;
184
187
  dsize--;
213
216
          }
214
217
          else
215
218
            break;
216
 
    if (--dsize<0)
 
219
    if (Dest!=NULL && --dsize<0)
217
220
      break;
218
221
    if (d>0xffff)
219
222
    {
220
 
      if (--dsize<0 || d>0x10ffff)
 
223
      if (Dest!=NULL && --dsize<0 || d>0x10ffff)
221
224
        break;
222
 
      *(Dest++)=((d-0x10000)>>10)+0xd800;
223
 
      *(Dest++)=(d&0x3ff)+0xdc00;
 
225
      if (Dest!=NULL)
 
226
      {
 
227
        *(Dest++)=((d-0x10000)>>10)+0xd800;
 
228
        *(Dest++)=(d&0x3ff)+0xdc00;
 
229
      }
224
230
    }
225
231
    else
226
 
      *(Dest++)=d;
 
232
      if (Dest!=NULL)
 
233
        *(Dest++)=d;
227
234
  }
228
 
  *Dest=0;
 
235
  if (Dest!=NULL)
 
236
    *Dest=0;
 
237
  return *Src==0; // Return success if we reached the end of source string.
229
238
}
230
239
 
231
240
 
295
304
}
296
305
 
297
306
 
 
307
int tolowerw(int ch)
 
308
{
 
309
#ifdef _WIN_ALL
 
310
  return((int)(LPARAM)CharLowerW((wchar *)(uint)ch));
 
311
#else
 
312
  return((ch<128) ? loctolower(ch):ch);
 
313
#endif
 
314
}
 
315
 
 
316
 
298
317
int atoiw(const wchar *s)
299
318
{
300
319
  int n=0;
328
347
 
329
348
char* SupportDBCS::charnext(const char *s)
330
349
{
331
 
  return (char *)(IsLeadByte[(byte)*s] ? s+2:s+1);
 
350
  // Zero cannot be the trail byte. So if next byte after the lead byte
 
351
  // is 0, the string is corrupt and we'll better return the pointer to 0,
 
352
  // to break string processing loops.
 
353
  return (char *)(IsLeadByte[(byte)*s] && s[1]!=0 ? s+2:s+1);
332
354
}
333
355
 
334
356