Browse Source

临时提交。

Jeff 4 năm trước cách đây
mục cha
commit
e9d302ee9b
2 tập tin đã thay đổi với 14 bổ sung10 xóa
  1. 13 9
      Serail-Demo/Demo/stdafx.cpp
  2. 1 1
      Serail-Demo/Demo/stdafx.h

+ 13 - 9
Serail-Demo/Demo/stdafx.cpp

@@ -7,16 +7,24 @@
 // TODO: 在 STDAFX.H 中
 // 引用任何所需的附加头文件,而不是在此文件中引用
 
-bool parse_key(std::string &value, TCHAR *lpszBuffer, TCHAR *lpszText)
+bool parse_key(std::string &RetValue, std::string strLine, TCHAR *lpszText)
 {
 	TCHAR szText[MAX_PATH] = {0};
 	TCHAR szValue[MAX_PATH] = {0};
+	// 去除空格;
+#if _MSC_VER > 1900
+	strLine.erase(std::remove_if(strLine.begin(), strLine.end(), [](unsigned char x) {return std::isspace(x); }), strLine.end()); //C++17
+#else
+	for (std::string::iterator it = strLine.begin(); it != strLine.end();)	{
+		isspace(*it) ? it++ : it = it = strLine.erase(it);
+	}
+#endif
 
-	if ( 2 == _stscanf_s(lpszBuffer, _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH) )
+	if ( 2 == _stscanf_s(strLine.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH) )
 	{
 		if ( _tcsstr(szText, lpszText) )
 		{
-			value = szValue;
+			RetValue = szValue;
 			return true;
 		}
 	}
@@ -26,7 +34,7 @@ bool parse_key(std::string &value, TCHAR *lpszBuffer, TCHAR *lpszText)
 
 int parse_cmd_param_from_file(char *file_name)
 {
-	char buf[256];
+	char buf[MAX_PATH] = {0};
 	TCHAR name[MAX_PATH] = {0};
 	TCHAR head[MAX_PATH] = {0};
 	TCHAR code[MAX_PATH] = {0};
@@ -51,7 +59,7 @@ int parse_cmd_param_from_file(char *file_name)
 		unsigned int protocol = 0;
 		unsigned int scancode = 0;
 
-		tmp_len = strlen((char*)buf);
+		tmp_len = _tcslen((char*)buf);
 		if(tmp_len >= 1) {
 			if (buf[tmp_len - 1] == '\r' || buf[tmp_len - 1] == '\n')
 				buf[tmp_len - 1] = 0;
@@ -61,10 +69,6 @@ int parse_cmd_param_from_file(char *file_name)
 			} 
 		}
 
-		// 先去除空格;
-		//std::string strline = buf;
-		// strline.erase(std::remove_if(strline.begin(), strline.end(), [](unsigned char x){return std::isspace(x); }), strline.end()); //C++17
-
 #if _MSC_VER >= 1500 
 		//if ( sscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%[^;]", name, MAX_PATH, head, MAX_PATH, code, MAX_PATH, mark, MAX_PATH, multicode, MAX_PATH, cmd_wait_time, MAX_PATH, read_wait_time, MAX_PATH) == 7)
 		if ( sscanf_s(buf, "%[^;];%[^;];%[^;];%[^;];%[^;];%[^;];%s", name, MAX_PATH, head, MAX_PATH, code, MAX_PATH, mark, MAX_PATH, multicode, MAX_PATH, cmd_wait_time, MAX_PATH, read_wait_time, MAX_PATH) == 7)

+ 1 - 1
Serail-Demo/Demo/stdafx.h

@@ -47,6 +47,6 @@ typedef struct __CMDPARAM__
 	int read_wait_time ;	// 写完串口后,等待多久读;
 } CommandParam, *pCommandParam;
 
-bool parse_key(std::string &value, TCHAR *lpszBuffer, TCHAR *lpszText);
+bool parse_key(std::string &value, std::string strLine, TCHAR *lpszText);
 int parse_cmd_param_from_file(char *file_name);
 // TODO: 在此处引用程序需要的其他头文件