00001 //===-- basic/Pragmas.cpp ------------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #include "comma/basic/Pragmas.h" 00010 00011 #include <cstring> 00012 00013 using namespace comma::pragma; 00014 00015 namespace { 00016 00017 static const char *pragmaNames[] = { 00018 "Assert", 00019 "Import" 00020 }; 00021 00022 } // end anonymous namespace. 00023 00024 const char *comma::pragma::getPragmaString(PragmaID ID) 00025 { 00026 return pragmaNames[ID - FIRST_PRAGMA]; 00027 } 00028 00029 PragmaID comma::pragma::getPragmaID(const char *start, const char *end) 00030 { 00031 size_t len = end - start; 00032 00033 for (unsigned cursor = FIRST_PRAGMA; cursor <= LAST_PRAGMA; ++cursor) { 00034 PragmaID ID = static_cast<PragmaID>(cursor); 00035 const char *name = getPragmaString(ID); 00036 if (::strlen(name) == len && strncmp(name, start, len) == 0) 00037 return ID; 00038 } 00039 return UNKNOWN_PRAGMA; 00040 }