mirror of
https://github.com/JasonYANG170/KeyBox.git
synced 2024-11-23 12:06:24 +00:00
add new code
This commit is contained in:
parent
dbc413594d
commit
462946a721
63
src/main.cpp
63
src/main.cpp
|
@ -24,10 +24,12 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
#include "SD.h"
|
#include "SD.h"
|
||||||
//配置数据结构
|
//配置数据结构
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int OutPutTimes;
|
int OutPutTimes;
|
||||||
|
|
||||||
String OutPutString = "";
|
String OutPutString = "";
|
||||||
int keySize;
|
int keySize;
|
||||||
|
|
||||||
|
@ -90,8 +92,21 @@ int db_exec(sqlite3 *db, const char *sql) {
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
void removeDuplicates(String arr[], int& n) {//此函数提供方法删除数组内重复的值
|
||||||
void addSiteDataToArr() {
|
for (int i = 0; i < n; i++) {
|
||||||
|
for (int j = i + 1; j < n;) {
|
||||||
|
if (arr[i] == arr[j]) {
|
||||||
|
for (int k = j; k < n - 1; k++) {
|
||||||
|
arr[k] = arr[k + 1];
|
||||||
|
}
|
||||||
|
n--;
|
||||||
|
} else {
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void addSiteDataToArr() {//此函数提供方法使其全部网站保存在数组中,界面分类用
|
||||||
sqlite3 *db1;
|
sqlite3 *db1;
|
||||||
|
|
||||||
char *zErrMsg = 0;
|
char *zErrMsg = 0;
|
||||||
|
@ -117,36 +132,36 @@ void addSiteDataToArr() {
|
||||||
const int SiteSize = OutPutTimes;
|
const int SiteSize = OutPutTimes;
|
||||||
|
|
||||||
String Site[SiteSize];//根据数据长度确认数组长度
|
String Site[SiteSize];//根据数据长度确认数组长度
|
||||||
std::string OutPutString = "id = 1\nsite = example_site_2\nuser = user1\npassword = password1\nid = 2\nsite = example_site_1\nuser = user3\npassword = password1\nid = 3\nsite = example.com\nuser = john_doe\npassword = password123";
|
// std::string OutPutString = "id = 1\nsite = example_site_2\nuser = user1\npassword = password1\nid = 2\nsite = example_site_1\nuser = user3\npassword = password1\nid = 3\nsite = example.com\nuser = john_doe\npassword = password123";
|
||||||
|
String inputString = OutPutString; // 输入的字符串
|
||||||
|
int startIndex = 0;
|
||||||
|
int endIndex = 0;
|
||||||
|
|
||||||
std::istringstream ss(OutPutString);
|
for(int i=0;i<OutPutTimes;i++) {
|
||||||
std::string line;
|
startIndex = inputString.indexOf("=", endIndex);
|
||||||
|
if (startIndex == -1) {
|
||||||
|
break; // 如果没有找到等号,退出循环
|
||||||
|
}
|
||||||
|
|
||||||
while (std::getline(ss, line, '\n')) {
|
endIndex = inputString.indexOf("\n", startIndex); // 查找换行符的位置
|
||||||
// Split the line based on '='
|
|
||||||
size_t found = line.find('=');
|
|
||||||
if (found != std::string::npos) {
|
|
||||||
std::string key = line.substr(0, found);
|
|
||||||
std::string value = line.substr(found + 1);
|
|
||||||
|
|
||||||
// Trim any leading/trailing spaces
|
if (endIndex == -1) {
|
||||||
key.erase(0, key.find_first_not_of(" \n\r\t"));
|
endIndex = inputString.length(); // 如果没有找到换行符,则使用字符串的末尾作为终点
|
||||||
key.erase(key.find_last_not_of(" \n\r\t") + 1);
|
}
|
||||||
value.erase(0, value.find_first_not_of(" \n\r\t"));
|
|
||||||
value.erase(value.find_last_not_of(" \n\r\t") + 1);
|
|
||||||
const char* cString = key.c_str();
|
|
||||||
|
|
||||||
// 输出C风格的字符串
|
String value = inputString.substring(startIndex + 2, endIndex); // 提取等号后面的内容,包括空格
|
||||||
Serial.println(cString);
|
|
||||||
Serial.println("+");
|
Serial.println(value);
|
||||||
const char* cString2 = value.c_str();
|
Site[i] = value;
|
||||||
|
|
||||||
// 输出C风格的字符串
|
|
||||||
Serial.println(cString2);
|
|
||||||
//std::cout << key << " = " << value << std::endl;
|
|
||||||
}
|
}
|
||||||
|
removeDuplicates(Site, OutPutTimes);
|
||||||
|
Serial.println("--------分割-----------");
|
||||||
|
for (int i = 0; i < OutPutTimes; i++) {
|
||||||
|
Serial.println(Site[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\
|
||||||
// OutPutString.
|
// OutPutString.
|
||||||
//
|
//
|
||||||
// char *token;
|
// char *token;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user