📄 ugkstyletable.cpp
字号:
// UGKStyleTable.cpp: implementation of the UGKStyleTable class.////////////////////////////////////////////////////////////////////////#include "ugkstyletable.h"#include "ugk_memopr.h"#include "ugk_string.h"/****************************************************************************//* UGKStyleTable::UGKStyleTable() *//* *//****************************************************************************/UGKStyleTable::UGKStyleTable(){ m_papszStyleTable = NULL;}/****************************************************************************//* UGKStyleTable::~UGKStyleTable() *//* *//****************************************************************************/UGKStyleTable::~UGKStyleTable(){ Clear();}/****************************************************************************//* GBool UGKStyleTable::AddStyle(char *pszName, *//* char *pszStyleString) *//* *//* Add a new style in the table, no comparaison will be done on the *//* Style string, only on the name, TRUE success, FALSE error *//****************************************************************************/UGKBool UGKStyleTable::AddStyle(const char *pszName, const char *pszStyleString){ int nPos; const char *pszNewString = NULL; if (pszName && pszStyleString) { if ((nPos = IsExist(pszName)) != -1) return FALSE; pszNewString = UGKSPrintf("%s:%s",pszName,pszStyleString); m_papszStyleTable = AddStringToList(m_papszStyleTable,pszNewString); return TRUE; } return FALSE;}/****************************************************************************//* void UGKStyleTable::Clear() *//* *//****************************************************************************/void UGKStyleTable::Clear(){ if (m_papszStyleTable) FreeStrList(m_papszStyleTable); m_papszStyleTable = NULL;}/****************************************************************************//* const char *UGKStyleTable::Find(const char *pszName) *//* *//* return the StyleString based on the gived name, *//* otherwise return NULL *//****************************************************************************/const char *UGKStyleTable::Find(const char *pszName){ const char *pszDash = NULL; const char *pszOutput = NULL; int nPos; if ((nPos = IsExist(pszName)) != -1) { pszOutput = GetStrFromList(m_papszStyleTable,nPos); pszDash = strstr(pszOutput,":"); if (pszDash) return &pszDash[1]; } return NULL;} /****************************************************************************//* const char *UGKStyleTable::GetStyleName(const char *pszStyleString) *//* *//* return the Name of a gived stylestring otherwise NULL *//****************************************************************************/const char *UGKStyleTable::GetStyleName(const char *pszStyleString){ int i; const char *pszStyleStringBegin; static char *pszName = NULL; char *pszTmp; if (pszName) UGK_Free(pszName); pszName = NULL; for (i=0;i<CountOfList(m_papszStyleTable);i++) { pszStyleStringBegin = strstr(m_papszStyleTable[i],":"); if (pszStyleStringBegin && EQUAL(&pszStyleStringBegin[1],pszStyleString) ) { pszName = UGKStrdup(m_papszStyleTable[i]); pszTmp = strstr(pszName,":"); if (pszTmp) pszTmp[0] = '\0'; break; } } return pszName;}/****************************************************************************//* GBool UGKStyleTable::IsExist(const char *pszName) *//* *//* return a index of the style in the table otherwise return -1 *//****************************************************************************/int UGKStyleTable::IsExist(const char *pszName){ int i; const char *pszNewString; if (pszName == NULL) return -1; pszNewString = UGKSPrintf("%s:",pszName);// for (i=0;i<CountOfList(m_papszStyleTable);i++) { if (strstr(m_papszStyleTable[i],pszNewString) != NULL) { return i; } } return -1;} /****************************************************************************//* GBool UGKStyleTable::LoadStyleTable(char *) *//* *//* Read the Style table from a file, return TRUE on success *//* otherwise return FALSE *//****************************************************************************/UGKBool UGKStyleTable::LoadStyleTable(const char *pszFilename){ if (pszFilename == NULL) return FALSE; FreeStrList(m_papszStyleTable); m_papszStyleTable = LoadFileToList(pszFilename); if (m_papszStyleTable == NULL) return FALSE; else return TRUE;}/****************************************************************************//* GBool UGKStyleTable::ModifyStyle(char *pszName, *//* char *pszStyleString) *//* *//* Modify the gived style, if the style doesn't exist, it will be added *//* return TRUE on success otherwise return FALSE *//****************************************************************************/UGKBool UGKStyleTable::ModifyStyle(const char *pszName, const char * pszStyleString){ if (pszName == NULL || pszStyleString == NULL) return FALSE; RemoveStyle(pszName); return AddStyle(pszName, pszStyleString);} /****************************************************************************//* UGKStyleTable::Print(FILE *fpOut) *//* *//****************************************************************************/void UGKStyleTable::Print(FILE *fpOut){ UGKFPrintf(fpOut,"#OFS-Version: 1.0\n"); UGKFPrintf(fpOut,"#StyleField: style\n"); if (m_papszStyleTable) { UGKPrint(m_papszStyleTable,fpOut); }}/****************************************************************************//* GBool UGKStyleTable::RemoveStyle(char *pszName) *//* *//* Remove the gived style in the table based on the name, return TRUE *//* on success otherwise FALSE *//****************************************************************************/UGKBool UGKStyleTable::RemoveStyle(const char *pszName){ int nPos; if ((nPos = IsExist(pszName)) != -1) { m_papszStyleTable = RemoveStringsFromList(m_papszStyleTable,nPos,1,NULL); return TRUE; } return FALSE;}/****************************************************************************//* GBool UGKStyleTable::SaveStyleTable(char *) *//* *//* Save the StyleTable in the gived file, return TRUE on success *//* otherwise return FALSE *//****************************************************************************/UGKBool UGKStyleTable::SaveStyleTable(const char *pszFilename){ if (pszFilename == NULL) return FALSE; if (SaveStringToTxt(m_papszStyleTable,pszFilename) == 0) return FALSE; else return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -