Exemplo n.º 1
0
void add_data_from_line(Memory& mem, string& line)
{
	regex regex_apostrophe("'");
	std::regex_replace(line, regex_apostrophe, "’");
	regex regex_word("([a-zA-záéíóúñÁÉÍÓÚÑ'’]+)");
	sregex_iterator find_word(line.begin(), line.end(), regex_word);
	for (sregex_iterator find_end; find_word != find_end; ++find_word) {
		string word_found = find_word->str();
		word_found = to_lower_case(word_found);
		update_word(mem.word_list, word_found);
	}
	vector<regex> regex_punc = {
		regex("\\."),
		regex(","),
		regex(";"),
		regex(":"),
		regex("!"),
		regex("\\?"),
		regex("(?:[-–—]\\s*){1,2}"),
		regex("…|(?:\\.\\s*){3}")
	};
	for (int i = 0; i < PUNC_NUM; ++i) {
		sregex_iterator find_punc(line.begin(), line.end(), regex_punc[i]);
		mem.punc_freq[i] += std::distance(find_punc, sregex_iterator());
	}
	regex regex_split_line("^([^.!?…]*[.!?…])?((?:[^.!?…]*[.!?…])*?)([^.!?…]*)$");
	std::sregex_token_iterator split_line_prev(line.begin(), line.end(), regex_split_line, 1);
	std::sregex_token_iterator split_line_cont(line.begin(), line.end(), regex_split_line, 2);
	std::sregex_token_iterator split_line_xtra(line.begin(), line.end(), regex_split_line, 3);
	string sentence_prev = *split_line_prev;
	int sentence_prev_len = get_word_count(sentence_prev);
	if (sentence_prev_len > 0) {
		sentence_prev_len += mem.sentence_carry;
		mem.sentence_len.push_back(sentence_prev_len);
		mem.sentence_carry = 0;
	}
	string sentence_cont = *split_line_cont;
	regex regex_split_sentence("([^\\.!?…]*)[\\.!?…]");
	sregex_iterator find_sentence(sentence_cont.begin(), sentence_cont.end(), regex_split_sentence);
	for (sregex_iterator find_end; find_sentence != find_end; ++find_sentence) {
		string sentence_found = find_sentence->str();
		int sentence_len = get_word_count(sentence_found);
		mem.sentence_len.push_back(sentence_len);
		mem.sentence_carry = 0;
	}
	string sentence_xtra = *split_line_xtra;
	int sentence_xtra_len = get_word_count(sentence_xtra);
	if (sentence_xtra_len > 0) {
		mem.sentence_carry += sentence_xtra_len;
	}
}
void handle_tick(AppContextRef ctx, PebbleTickEvent *t) {
  (void)t;

	PblTm currentTime;
	static char timeTextM[] = "00";
	static char timeTextH[] = "00";

  first_run = "false";
	font_minutes_word.old_text = font_minutes_word.text;
	hours_word.old_text = hours_word.text;
	
	get_time(&currentTime);
	
	string_format_time(timeTextM, sizeof(timeTextM), "%M", &currentTime);
	font_minutes_word.text = timeTextM;

	string_format_time(timeTextH, sizeof(timeTextH), "%H", &currentTime);
	hours_word.text = timeTextH;
	
	update_word(&font_minutes_word);
  update_hand_positions();
}
Exemplo n.º 3
0
/** Called once per minute */
static void
handle_tick(
	AppContextRef ctx,
	PebbleTickEvent * const event
)
{
	(void) ctx;
	const PblTm * const ptm = event->tick_time;

	int hour = ptm->tm_hour;
	int min = ptm->tm_min;

	kpi3_word.old_text = kpi3_word.text;
	kpi2_word.old_text = kpi2_word.text;
	kpi1_word.old_text = kpi1_word.text;
	ampm_word.old_text = ampm_word.text;
	hour_word.old_text = hour_word.text;
	rel_word.old_text = rel_word.text;
	min_word.old_text = min_word.text;

	nederlands_format(hour,  min);

/*
	string_format_time(
		time_buffer,
		sizeof(time_buffer),
		"%H:%M",
		event->tick_time
	);
*/

	update_word(&kpi3_word);
	update_word(&kpi2_word);
	update_word(&kpi1_word);
	update_word(&ampm_word);
	update_word(&hour_word);
	update_word(&rel_word);
	update_word(&min_word);
}