프로그래밍/boost
boost 정규식 이용한 파일 만들기..
널부러
2013. 5. 3. 18:41
#include "stdafx.h" #include <iostream> #include <regex> #include <fstream> #include "errorDefine.h" int _tmain(int argc, _TCHAR* argv[]) { std::ifstream openFile; openFile.open("errorDefine.h"); if( !openFile.is_open() ) { return 0; } // 파싱할 내용 std::regex startEndRegex( "[{}]" ); std::regex indexRegex ("(-?[0-9]+),[^0-9]"); std::regex defineRegex ("[0-9a-zA-Z_]+"); std::regex logMessageRegex("// "); int index = 0; bool startPrint = false; while( openFile.good() ) { std::string stringLine; std::string defineString; std::string logMessage; std::smatch indexMatch; std::smatch defineMatch; std::smatch logMessageMatch; std::smatch startEndMatch; // 파일 읽기 std::getline( openFile, stringLine ); // 공백 체크 stringLine.erase( stringLine.find_last_not_of(' ') + 1 ); if( 0 == stringLine.length() ) continue; // 시작 끝 체크 if( true == std::regex_search(stringLine, startEndMatch, startEndRegex) ) { startPrint = !startPrint; continue; } // 출력 여부 확인 if( false == startPrint ) continue; // define 인덱스 출력 std::regex_search(stringLine,indexMatch,indexRegex); if( !indexMatch.empty() ) { std::string tempIndex = indexMatch[0]; index = atoi( tempIndex.c_str() ); } else { index++; } // define Name std::regex_search(stringLine, defineMatch, defineRegex); if( !defineMatch.empty() ) { defineString = defineMatch[0]; } // define 메시지 std::regex_search(stringLine, logMessageMatch,logMessageRegex); if( !logMessageMatch.empty() ) { logMessage = logMessageMatch[0].second._Ptr; } else { logMessage = "***메시지가 없음 추가요망"; } // 출력 printf("index : %5d - defineName : %s - message : %s\n", index, defineString.c_str(), logMessage.c_str() ); } return 0; }=== errorDefine.h
enum errorType { RESULT_FAIL = -1, // 에러 RESULT_OK, // 정상 ERROR_1, // 에러 메시지 출력(1번이에용) ERROR_2, // 에러 메시지 출력(2번이에용) ERROR_3, // ERROR_4 = 100, // 중간에 변경된 번호야 ERROR_TYPE_MAX, // 에러 번호 끝 };