Merge pull request #4324 from FernetMenta/wasapi
[vuplus_xbmc] / lib / UnrarXLib / strfn.cpp
1 #include "rar.hpp"
2
3 const char *NullToEmpty(const char *Str)
4 {
5   return(Str==NULL ? "":Str);
6 }
7
8
9 const wchar *NullToEmpty(const wchar *Str)
10 {
11   return(Str==NULL ? L"":Str);
12 }
13
14
15 char *IntNameToExt(const char *Name)
16 {
17   static char OutName[NM];
18   IntToExt(Name,OutName);
19   return(OutName);
20 }
21
22
23 void ExtToInt(const char *Src,char *Dest)
24 {
25 #if defined(_WIN_32)
26   CharToOem(Src,Dest);
27 #else
28   if (Dest!=Src)
29     strcpy(Dest,Src);
30 #endif
31 }
32
33
34 void IntToExt(const char *Src,char *Dest)
35 {
36 #if defined(_WIN_32)
37   OemToChar(Src,Dest);
38 #else
39   if (Dest!=Src)
40     strcpy(Dest,Src);
41 #endif
42 }
43
44
45 char* strlower(char *Str)
46 {
47 #ifdef _WIN_32
48   CharLower((LPTSTR)Str);
49 #else
50   for (char *ChPtr=Str;*ChPtr;ChPtr++)
51     *ChPtr=(char)loctolower(*ChPtr);
52 #endif
53   return(Str);
54 }
55
56
57 char* strupper(char *Str)
58 {
59 #ifdef _WIN_32
60   CharUpper((LPTSTR)Str);
61 #else
62   for (char *ChPtr=Str;*ChPtr;ChPtr++)
63     *ChPtr=(char)loctoupper(*ChPtr);
64 #endif
65   return(Str);
66 }
67
68
69 int stricomp(const char *Str1,const char *Str2)
70 {
71   char S1[NM*2],S2[NM*2];
72   strncpy(S1,Str1,sizeof(S1));
73   strncpy(S2,Str2,sizeof(S2));
74   return(strcmp(strupper(S1),strupper(S2)));
75 }
76
77
78 int strnicomp(const char *Str1,const char *Str2,int N)
79 {
80   char S1[512],S2[512];
81   strncpy(S1,Str1,sizeof(S1));
82   strncpy(S2,Str2,sizeof(S2));
83   return(strncmp(strupper(S1),strupper(S2),N));
84 }
85
86
87 char* RemoveEOL(char *Str)
88 {
89   for (int I=strlen(Str)-1;I>=0 && (Str[I]=='\r' || Str[I]=='\n' || Str[I]==' ' || Str[I]=='\t');I--)
90     Str[I]=0;
91   return(Str);
92 }
93
94
95 char* RemoveLF(char *Str)
96 {
97   for (int I=strlen(Str)-1;I>=0 && (Str[I]=='\r' || Str[I]=='\n');I--)
98     Str[I]=0;
99   return(Str);
100 }
101
102
103 unsigned int loctolower(byte ch)
104 {
105 #ifdef _WIN_32
106   return((int)CharLower((LPTSTR)ch));
107 #else
108   return(tolower(ch));
109 #endif
110 }
111
112
113 unsigned int loctoupper(byte ch)
114 {
115 #ifdef _WIN_32
116   return((int)CharUpper((LPTSTR)ch));
117 #else
118   return(toupper(ch));
119 #endif
120 }
121
122
123
124
125
126 bool LowAscii(const char *Str)
127 {
128   for (int I=0;Str[I]!=0;I++)
129     if ((byte)Str[I]<32 || (byte)Str[I]>127)
130       return(false);
131   return(true);
132 }
133
134
135 bool LowAscii(const wchar *Str)
136 {
137   for (int I=0;Str[I]!=0;I++)
138     if (Str[I]<32 || Str[I]>127)
139       return(false);
140   return(true);
141 }