1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "SourceFile.h"
-
- #include <iostream>
- #include <fstream>
- #include <sstream>
-
- static bool startsWith(const std::string &a, const std::string &b, std::string &after) {
- if (a.size() < b.size())
- return false;
-
- for (size_t i = 0; i < b.size(); ++i) {
- if (a[i] != b[i])
- return false;
- }
-
- after = a.substr(b.size());
- return true;
- }
-
- static void parseParts(std::vector<std::string> &vec, const std::string &str) {
- std::istringstream ss(str);
- std::string part;
- while (ss >> part) {
- vec.push_back(part);
- }
- }
-
- SourceFile::SourceFile(std::string dir, std::string name):
- dir_(std::move(dir)), name_(std::move(name)) {
-
- std::ifstream file(dir_ + "/" + name_);
-
- std::string line;
- std::string content;
- while (std::getline(file, line)) {
- if (line.size() < 4) continue;
- if (line[0] != '/' || line[1] != '/' || line[2] != '#') continue;
-
- if (startsWith(line, "//# pkgs:", content)) {
- parseParts(pkgs_, content);
- } else if (startsWith(line, "//# cflags:", content)) {
- parseParts(pkgs_, content);
- } else if (startsWith(line, "//# ldflags:", content)) {
- parseParts(pkgs_, content);
- }
- }
- }
|