・CWorkspace::GetKeySwapStringで、自動置き換えが正常に動作しないバグを修正
・CWorkspaceで無駄に引数を参照渡しにしていたのを値渡しに修正(CString型のコピーは高速なので、実行速度への影響は小さい)
@@ -400,14 +400,31 @@ | ||
400 | 400 | if(tempSwap != NULL) |
401 | 401 | AddAutoSwap(tempSwap); |
402 | 402 | |
403 | + // ノードパスに | |
404 | + path = ToNodePath(path); | |
405 | + | |
406 | + // 対象ノードを取得 | |
403 | 407 | CString key; |
404 | - CWorkspaceNode * node = GetSubNode(path,key); | |
405 | - CString data = node->GetKeySwapString(str,noData); | |
408 | + CWorkspaceNode * node = GetSubNode(path, key); | |
406 | 409 | |
410 | + // 全キーを取得 | |
411 | + CStringArray keyList; | |
412 | + node->GetAllKey(keyList); | |
413 | + | |
414 | + // 全部置換 | |
415 | + for(int i=0;i<keyList.GetCount();i++) | |
416 | + { | |
417 | + str.Replace("%" + keyList[i] + "%", GetKeyData(path + keyList[i], _T(""), FALSE)); | |
418 | + } | |
419 | + | |
420 | + // 残った%〜%を置換 | |
421 | + if(!noData.IsEmpty() && noData.Find("%") == -1) | |
422 | + str = CTextTools::SwapKeySandString(_T("%"), str, noData); | |
423 | + | |
407 | 424 | if(tempSwap != NULL) |
408 | 425 | DelAutoSwap(tempSwap); |
409 | 426 | |
410 | - return(data); | |
427 | + return(str); | |
411 | 428 | } |
412 | 429 | |
413 | 430 | ///////////////////////////////////////////////////////////////////////////////////// |
@@ -47,6 +47,12 @@ | ||
47 | 47 | static int FindStrIndex(CStringArray &list, CString find, int noCase = 0); |
48 | 48 | |
49 | 49 | ////////////////////////////////////////////////////////////// |
50 | + // 置換処理 | |
51 | + ////////////////////////////////////////////////////////////// | |
52 | + //! <KEY>〜<KEY>を置換する。<KEY><KEY>は残す | |
53 | + static CString SwapKeySandString(CString sandKey, CString str, CString swap); | |
54 | + | |
55 | + ////////////////////////////////////////////////////////////// | |
50 | 56 | // 文字列変換 |
51 | 57 | ////////////////////////////////////////////////////////////// |
52 | 58 | //! Unicodeから、ANSI文字列へ |
@@ -39,16 +39,16 @@ | ||
39 | 39 | Keyに関する処理 |
40 | 40 | **********************************************************/ |
41 | 41 | //! データの設定 |
42 | - void SetKeyData(CString &key, CString &data,int noCase); | |
42 | + void SetKeyData(CString key, CString data,int noCase); | |
43 | 43 | |
44 | 44 | //! データの取得 |
45 | - CString GetKeyData(CString &key, CString &defaultData, int noCase); | |
45 | + CString GetKeyData(CString key, CString defaultData, int noCase); | |
46 | 46 | |
47 | 47 | //! キーの存在を確認 |
48 | - virtual int KeyIsExist(CString &key,int noCase=FALSE); | |
48 | + virtual int KeyIsExist(CString key,int noCase=FALSE); | |
49 | 49 | |
50 | 50 | //! データの削除 |
51 | - void DeleteKey(CString &key,int noCase=FALSE); | |
51 | + void DeleteKey(CString key,int noCase=FALSE); | |
52 | 52 | |
53 | 53 | //! キー数を取得 |
54 | 54 | int GetKeyCount(); |
@@ -60,7 +60,7 @@ | ||
60 | 60 | void CopyAllKeys(CKeyDataArray &keyData); |
61 | 61 | |
62 | 62 | //! 文字列中のキー名をデータに置き換えた文字列を取得する |
63 | - CString GetKeySwapString(CString str,CString noData); | |
63 | +// CString GetKeySwapString(CString str,CString noData); | |
64 | 64 | |
65 | 65 | //! キーを検索 |
66 | 66 | int FindKeyData(CString sData, int noCase = FALSE); |
@@ -44,7 +44,7 @@ | ||
44 | 44 | |
45 | 45 | このノードのデータに対するアクセス |
46 | 46 | */ |
47 | -void CWorkspaceNode::SetKeyData(CString &key, CString &data,int noCase) | |
47 | +void CWorkspaceNode::SetKeyData(CString key, CString data,int noCase) | |
48 | 48 | { |
49 | 49 | int index = FindKeyIndex(key,noCase); |
50 | 50 | if(index == -1) |
@@ -62,7 +62,7 @@ | ||
62 | 62 | |
63 | 63 | このノードのデータに対するアクセス |
64 | 64 | */ |
65 | -CString CWorkspaceNode::GetKeyData(CString &key, CString &defaultData, int noCase) | |
65 | +CString CWorkspaceNode::GetKeyData(CString key, CString defaultData, int noCase) | |
66 | 66 | { |
67 | 67 | int index = FindKeyIndex(key,noCase); |
68 | 68 | if(index == -1) |
@@ -80,7 +80,7 @@ | ||
80 | 80 | |
81 | 81 | このノードのデータに対するアクセス |
82 | 82 | */ |
83 | -int CWorkspaceNode::KeyIsExist(CString &key, int noCase) | |
83 | +int CWorkspaceNode::KeyIsExist(CString key, int noCase) | |
84 | 84 | { |
85 | 85 | int index = FindKeyIndex(key,noCase); |
86 | 86 | if(index != -1) |
@@ -93,7 +93,7 @@ | ||
93 | 93 | |
94 | 94 | このノードのデータに対するアクセス |
95 | 95 | */ |
96 | -void CWorkspaceNode::DeleteKey(CString &key, int noCase) | |
96 | +void CWorkspaceNode::DeleteKey(CString key, int noCase) | |
97 | 97 | { |
98 | 98 | int index = FindKeyIndex(key,noCase); |
99 | 99 | if(index != -1) |
@@ -139,6 +139,7 @@ | ||
139 | 139 | %Key-Name% を、該当するキーのデータで置き換えます |
140 | 140 | noDataが設定されている場合、見つからない場合は、noDataに置き換えます |
141 | 141 | */ |
142 | +/* | |
142 | 143 | CString CWorkspaceNode::GetKeySwapString(CString str,CString noData) |
143 | 144 | { |
144 | 145 | int count = (int)m_keyData.GetSize(); |
@@ -146,16 +147,6 @@ | ||
146 | 147 | // 全部検索 |
147 | 148 | for(int i=0;i<count;i++) |
148 | 149 | { |
149 | - /* | |
150 | - int index = str.Find("%" + m_keyData[i].m_key + "%"); | |
151 | - | |
152 | - for(int j=0;j<100 && index != -1;j++) | |
153 | - { | |
154 | - str = str.Mid(0,index) + m_keyData[i].m_data + str.Mid(index + 2 + m_keyData[i].m_key.GetLength()); | |
155 | - index = str.Find("%" + m_keyData[i].m_key + "%"); | |
156 | - } | |
157 | - */ | |
158 | - | |
159 | 150 | str.Replace("%" + m_keyData[i].m_key + "%",m_keyData[i].m_data); |
160 | 151 | } |
161 | 152 |
@@ -200,6 +191,7 @@ | ||
200 | 191 | |
201 | 192 | return(str); |
202 | 193 | } |
194 | +*/ | |
203 | 195 | |
204 | 196 | /*! |
205 | 197 | キーを検索 |
@@ -250,6 +250,48 @@ | ||
250 | 250 | } |
251 | 251 | |
252 | 252 | ////////////////////////////////////////////////////////////// |
253 | +// 置換処理 | |
254 | +////////////////////////////////////////////////////////////// | |
255 | +/*! | |
256 | + <KEY>〜<KEY>を置換する。<KEY><KEY>は残す | |
257 | +*/ | |
258 | +CString CTextTools::SwapKeySandString(CString sandKey, CString str, CString swap) | |
259 | +{ | |
260 | + CString ret; | |
261 | + while(1) | |
262 | + { | |
263 | + // 最初のキーを検索 | |
264 | + int index = str.Find(sandKey); | |
265 | + if(index == -1) | |
266 | + { | |
267 | + ret += str; | |
268 | + break; | |
269 | + } | |
270 | + | |
271 | + // 最初のキーまで切り出し | |
272 | + ret += str.Mid(0, index); | |
273 | + str = str.Mid(index + sandKey.GetLength()); | |
274 | + | |
275 | + // 挟むキーを検索 | |
276 | + int index2 = str.Find(sandKey); | |
277 | + if(index == -1) | |
278 | + { | |
279 | + ret += str; | |
280 | + break; | |
281 | + } | |
282 | + | |
283 | + // <KEY><KEY> | |
284 | + if(index2 == 0) | |
285 | + ret += sandKey; | |
286 | + else | |
287 | + ret += swap; | |
288 | + str = str.Mid(index2 + + sandKey.GetLength()); | |
289 | + } | |
290 | + | |
291 | + return(ret); | |
292 | +} | |
293 | + | |
294 | +////////////////////////////////////////////////////////////// | |
253 | 295 | // 文字列変換 |
254 | 296 | ////////////////////////////////////////////////////////////// |
255 | 297 | /*! |