zoukankan      html  css  js  c++  java
  • 给COCO数据集的json标签换行

    //针对COCO标签只有单行,打开/修改非常慢的问题(虽然本程序跑起来也不快,但至少以后用Notepad++修改起来会快点)

    #include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; int main(){ ifstream src("原.json"); ofstream dst("新.json"); string getall; getline(src, getall); string space = " "; size_t count_of_space = 0; size_t n = getall.size(); bool inmark = false; for (size_t i = 0; i < n; ++i){ char c = getall[i]; if (c < 1)break; //printf("%c[%d/%d] ", c, i, n); if (c == '"'){ inmark = !inmark; } if (inmark){ dst << c; continue; } switch (c){ case '[': case '{': count_of_space += 1; dst << c << ' '; for (size_t j = 0; j < count_of_space; ++j)dst << space; break; case ']': count_of_space -= 1; if (count_of_space < 0)count_of_space = 0; dst << ' '; for (size_t j = 0; j < count_of_space; ++j)dst << space; dst << ']'; if (i + 3 < n){ if (getall[i + 1] != ','&&getall[i + 2] != ',')dst << ' '; } break; case '}': count_of_space -= 1; if (count_of_space < 0)count_of_space = 0; dst << ' '; for (size_t j = 0; j < count_of_space; ++j)dst << space; dst << '}'; if (i + 3 < n){ if(getall[i + 1] != ','&&getall[i + 2] != ',')dst << ' '; } break; case ',': dst << ','; case ' ': dst << ' '; if (count_of_space < 0)count_of_space = 0; for (size_t j = 0; j < count_of_space; ++j)dst << space; break; default: dst << c; break; } } return 0; }
  • 相关阅读:
    Prometheus监控MySQL服务(六)
    Prometheus监控Docker服务(五)
    Grafana与Prometheus集成(四)
    Prometheus监控Linux服务器(三)
    Prometheus配置文件(二)
    elasticdump数据迁移方法
    Prometheus介绍及二进制部署(一)
    PHP二维数组的引用赋值容易犯的错误
    Maven仓库国内镜像站
    加密文件之Java改进版
  • 原文地址:https://www.cnblogs.com/aimhabo/p/10413824.html
Copyright © 2011-2022 走看看