refactor: MakeTempSatPath 并入已有的 SAT 相关 namespace
- 不再为单个函数新建 namespace 块:把 SAT 相关的 find_nth_occurrence_reverse / fixACISFormat 整块上移到 RegionToString 之前, MakeTempSatPath 并入同一块,文件内 namespace 块数由 7 回到 6 - 编码规范补充:优先复用已有 namespace,整个文件没有时才新建
This commit is contained in:
1 parent
27cd7111fb
commit
3ba658ffc5
2 files changed
+50
-53
No files matched your search
+1
-1
@@ -146,7 +146,7 @@ set_debug_post_build(<target> "<Name>" ".arx")
|
|||||||
|
|
||||||
## 编码规范
|
## 编码规范
|
||||||
|
|
||||||
- **文件内私有函数用匿名 `namespace`**:只在一个 `.cpp` 内使用的函数,直接实现在该文件的匿名 `namespace { }` 中,不要写成文件级 `static`,也不要放进头文件。
|
- **文件内私有函数用匿名 `namespace`**:只在一个 `.cpp` 内使用的函数,直接实现在该文件**已有的**匿名 `namespace { }` 中;只有整个文件没有匿名 namespace 时才新建一块。不要为每个函数单独开一块,也不要写成文件级 `static` 或放进头文件。
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
@@ -3052,6 +3052,55 @@ CString MakeTempSatPath()
|
|||||||
sName.Format(_T("\\x3d_%lu_%ld.sat"), (unsigned long)::GetCurrentProcessId(), nSeq);
|
sName.Format(_T("\\x3d_%lu_%ld.sat"), (unsigned long)::GetCurrentProcessId(), nSeq);
|
||||||
return sPath + sName;
|
return sPath + sName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t find_nth_occurrence_reverse(const std::string &str, char target, size_t n)
|
||||||
|
{
|
||||||
|
size_t pos = str.size();
|
||||||
|
size_t count = 0;
|
||||||
|
|
||||||
|
while (pos > 0)
|
||||||
|
{
|
||||||
|
pos = str.rfind(target, pos - 1); // 从 pos-1 开始反向查找
|
||||||
|
if (pos == std::string::npos) break;
|
||||||
|
count++;
|
||||||
|
if (count == n) return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::string::npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 整理sat文件格式,使其符合规范
|
||||||
|
bool fixACISFormat(const char *pszReg, std::string &sOut)
|
||||||
|
{
|
||||||
|
// 先取第一行,得到data record 的数量
|
||||||
|
std::string ss;
|
||||||
|
std::stringstream eam(pszReg);
|
||||||
|
std::getline(eam, ss);
|
||||||
|
if (ss.empty()) return false;
|
||||||
|
|
||||||
|
std::vector<CString> nums;
|
||||||
|
CoreTools::SplitString(CString(ss.c_str()), _T(" "), nums);
|
||||||
|
if (nums.size() < 2) return false;
|
||||||
|
int countOfRecord = _ttoi((LPCTSTR)nums[1]);
|
||||||
|
|
||||||
|
ss = pszReg;
|
||||||
|
int sharpCount = std::count(ss.begin() ,ss.end(), '#');
|
||||||
|
|
||||||
|
size_t pos(std::string::npos);
|
||||||
|
if (sharpCount > countOfRecord)
|
||||||
|
{
|
||||||
|
// 如果 sharpCount 大于 countOfRecord,从头部取到第sharpCount个‘#’位置
|
||||||
|
pos = find_nth_occurrence_reverse(ss, '#', (sharpCount - countOfRecord + 1));
|
||||||
|
}
|
||||||
|
else // <=
|
||||||
|
{
|
||||||
|
// 如果 sharpCount 小于等于 countOfRecord,直接从头部取到最后一个‘#’位置
|
||||||
|
pos = ss.rfind('#');
|
||||||
|
}
|
||||||
|
sOut = ss.substr(0, pos + 1);
|
||||||
|
sOut += "\n\r";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Adesk::UInt64 CoreTools::RegionToString(const AcDbRegion *pReg, char *& pszTxt)
|
Adesk::UInt64 CoreTools::RegionToString(const AcDbRegion *pReg, char *& pszTxt)
|
||||||
@@ -3459,58 +3508,6 @@ bool CoreTools::CurveToString(const AcDbCurve * pCurve, CString & sScr2)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
size_t find_nth_occurrence_reverse(const std::string &str, char target, size_t n)
|
|
||||||
{
|
|
||||||
size_t pos = str.size();
|
|
||||||
size_t count = 0;
|
|
||||||
|
|
||||||
while (pos > 0)
|
|
||||||
{
|
|
||||||
pos = str.rfind(target, pos - 1); // 从 pos-1 开始反向查找
|
|
||||||
if (pos == std::string::npos) break;
|
|
||||||
count++;
|
|
||||||
if (count == n) return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::string::npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 整理sat文件格式,使其符合规范
|
|
||||||
bool fixACISFormat(const char *pszReg, std::string &sOut)
|
|
||||||
{
|
|
||||||
// 先取第一行,得到data record 的数量
|
|
||||||
std::string ss;
|
|
||||||
std::stringstream eam(pszReg);
|
|
||||||
std::getline(eam, ss);
|
|
||||||
if (ss.empty()) return false;
|
|
||||||
|
|
||||||
std::vector<CString> nums;
|
|
||||||
CoreTools::SplitString(CString(ss.c_str()), _T(" "), nums);
|
|
||||||
if (nums.size() < 2) return false;
|
|
||||||
int countOfRecord = _ttoi((LPCTSTR)nums[1]);
|
|
||||||
|
|
||||||
ss = pszReg;
|
|
||||||
int sharpCount = std::count(ss.begin() ,ss.end(), '#');
|
|
||||||
|
|
||||||
size_t pos(std::string::npos);
|
|
||||||
if (sharpCount > countOfRecord)
|
|
||||||
{
|
|
||||||
// 如果 sharpCount 大于 countOfRecord,从头部取到第sharpCount个‘#’位置
|
|
||||||
pos = find_nth_occurrence_reverse(ss, '#', (sharpCount - countOfRecord + 1));
|
|
||||||
}
|
|
||||||
else // <=
|
|
||||||
{
|
|
||||||
// 如果 sharpCount 小于等于 countOfRecord,直接从头部取到最后一个‘#’位置
|
|
||||||
pos = ss.rfind('#');
|
|
||||||
}
|
|
||||||
sOut = ss.substr(0, pos + 1);
|
|
||||||
sOut += "\n\r";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AcDbRegion* CoreTools::StringToRegion(const CString & sRegionScrp)
|
AcDbRegion* CoreTools::StringToRegion(const CString & sRegionScrp)
|
||||||
{
|
{
|
||||||
std::string sUtf8 = CoreTools::unicode2Ansii((LPCTSTR)sRegionScrp, CP_UTF8);
|
std::string sUtf8 = CoreTools::unicode2Ansii((LPCTSTR)sRegionScrp, CP_UTF8);
|
||||||
|
|||||||
Reference in new issue
Block a user