1 #include "CppBase.h"
2 #include "Internal.h"
3
4 namespace Upp {
5
IsCPPFile(const String & path)6 bool IsCPPFile(const String& path)
7 {
8 return findarg(ToLower(GetFileExt(path)) , ".c", ".cpp", ".cc" , ".cxx", ".icpp") >= 0;
9 }
10
IsHFile(const String & path)11 bool IsHFile(const String& path)
12 {
13 return findarg(ToLower(GetFileExt(path)) , ".h", ".hpp", ".hxx" , ".hh") >= 0;
14 }
15
SetSpaces(String & l,int pos,int count)16 void SetSpaces(String& l, int pos, int count)
17 {
18 StringBuffer s(l);
19 memset(~s + pos, ' ', count);
20 l = s;
21 }
22
SkipString(const char * s)23 const char *SkipString(const char *s)
24 {
25 CParser p(s);
26 try {
27 p.ReadOneString(*s);
28 }
29 catch(CParser::Error) {}
30 s = p.GetPtr();
31 while((byte)*(s - 1) <= ' ')
32 s--;
33 return s;
34 }
35
RemoveComments(String & l,bool & incomment)36 void RemoveComments(String& l, bool& incomment)
37 {
38 int q = -1;
39 int w = -1;
40 if(incomment)
41 q = w = 0;
42 else {
43 const char *s = l;
44 while(*s) {
45 if(*s == '\"')
46 s = SkipString(s);
47 else
48 if(s[0] == '/' && s[1] == '/') {
49 q = int(s - ~l);
50 SetSpaces(l, q, l.GetCount() - q);
51 return;
52 }
53 else
54 if(s[0] == '/' && s[1] == '*') {
55 q = int(s - ~l);
56 break;
57 }
58 else
59 s++;
60 }
61 if(q >= 0)
62 w = q + 2;
63 }
64 while(q >= 0) {
65 int eq = l.Find("*/", w);
66 if(eq < 0) {
67 incomment = true;
68 SetSpaces(l, q, l.GetCount() - q);
69 return;
70 }
71 SetSpaces(l, q, eq + 2 - q);
72 incomment = false;
73 q = l.Find("/*");
74 w = q + 2;
75 }
76 }
77
78 };