#include "phonefont.h"

const std::string PhoneFont::phonePad[] = {"2", "22", "222", "3", "33", "333", "4", "44", "444", "5", "55", "555", "6", "66", "666", "7", "77", "777", "7777", "8", "88", "888", "9", "99", "999", "9999"};

PhoneFont::PhoneFont() {}

void PhoneFont::applyFont(const std::string& in, std::string& out) const {
	bool wasPrevSpace = true;
	for(size_t pos_in = 0; pos_in < in.size(); ++pos_in) {
		char c = in[pos_in];
		bool isSpace = std::isspace(c);

		if(!wasPrevSpace && !isSpace) {
			out += '-';
		}

		if(c >= 'a' && c <= 'z') {
			out += phonePad[c - 'a'];
		} else if(c >= 'A' && c <= 'Z') {
			out += phonePad[c - 'A'];
		} else {
			out += c;
		}

		wasPrevSpace = isSpace;
	}
}

const std::string& PhoneFont::getName() const {
	static const std::string name = "Old Phone";
	return name;
}

bool PhoneFont::canApply(const std::string& in) const {
	return true;
}