Use folly's split instead of custom split in day2

master
Nick Krichevsky 2020-12-02 02:15:44 -05:00
parent b83b0a098b
commit 05237669a0
2 changed files with 21 additions and 2 deletions

15
day2/Makefile Normal file
View File

@ -0,0 +1,15 @@
CC=g++
BIN_NAME=day2
CCFLAGS=-o $(BIN_NAME)
LDFLAGS=-lfolly
.PHONY: all, clean
all: $(BIN_NAME)
clean:
rm -f $(BIN_NAME)
$(BIN_NAME):
$(CC) $(CCFLAGS) $(LDFLAGS) day2.cpp

View File

@ -1,3 +1,5 @@
#include <folly/String.h>
#include <algorithm>
#include <exception>
#include <fstream>
@ -75,8 +77,10 @@ class Entry {
*/
static Entry parse(const std::string &input) {
int delimIndex = input.find(DELIM);
std::string rawPolicy = input.substr(0, delimIndex);
std::string password = input.substr(delimIndex + DELIM.length());
std::vector<std::string> components;
folly::split(DELIM, input, components);
std::string rawPolicy = components.at(0);
std::string password = components.at(1);
Policy policy = Policy::parse(rawPolicy);
return Entry(policy, password);