#include "CppBase.h" #include "Internal.h" namespace Upp { bool IsCPPFile(const String& path) { return findarg(ToLower(GetFileExt(path)) , ".c", ".cpp", ".cc" , ".cxx", ".icpp") >= 0; } bool IsHFile(const String& path) { return findarg(ToLower(GetFileExt(path)) , ".h", ".hpp", ".hxx" , ".hh") >= 0; } void SetSpaces(String& l, int pos, int count) { StringBuffer s(l); memset(~s + pos, ' ', count); l = s; } const char *SkipString(const char *s) { CParser p(s); try { p.ReadOneString(*s); } catch(CParser::Error) {} s = p.GetPtr(); while((byte)*(s - 1) <= ' ') s--; return s; } void RemoveComments(String& l, bool& incomment) { int q = -1; int w = -1; if(incomment) q = w = 0; else { const char *s = l; while(*s) { if(*s == '\"') s = SkipString(s); else if(s[0] == '/' && s[1] == '/') { q = int(s - ~l); SetSpaces(l, q, l.GetCount() - q); return; } else if(s[0] == '/' && s[1] == '*') { q = int(s - ~l); break; } else s++; } if(q >= 0) w = q + 2; } while(q >= 0) { int eq = l.Find("*/", w); if(eq < 0) { incomment = true; SetSpaces(l, q, l.GetCount() - q); return; } SetSpaces(l, q, eq + 2 - q); incomment = false; q = l.Find("/*"); w = q + 2; } } };