Use folly's split instead of custom split in day2

This commit is contained in:
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 <algorithm>
#include <exception> #include <exception>
#include <fstream> #include <fstream>
@ -75,8 +77,10 @@ class Entry {
*/ */
static Entry parse(const std::string &input) { static Entry parse(const std::string &input) {
int delimIndex = input.find(DELIM); int delimIndex = input.find(DELIM);
std::string rawPolicy = input.substr(0, delimIndex); std::vector<std::string> components;
std::string password = input.substr(delimIndex + DELIM.length()); folly::split(DELIM, input, components);
std::string rawPolicy = components.at(0);
std::string password = components.at(1);
Policy policy = Policy::parse(rawPolicy); Policy policy = Policy::parse(rawPolicy);
return Entry(policy, password); return Entry(policy, password);