Example #1
0
void SeessionID::push_back(const std::string & sid, const std::string str) {
	WriteLock w_lock(myLock);
	std::vector<std::string> value;
	boost::regex regex1(" ", boost::regbase::normal | boost::regbase::icase);
	std::string mstr = str;
	boost::regex_split(std::back_inserter(value), mstr, regex1);
	for (int i = 0; i < (int) value.size(); i++) {
		if (!value[i].empty()) {
			if (ptrsmap[sid].ptr_s.empty()) {
				ptrsmap[sid].ptr_s.push_back(value[i]);
			} else {
				bool find = false;
				for (unsigned int j = 0; j < ptrsmap[sid].ptr_s.size(); j++) {
					if (ptrsmap[sid].ptr_s[j] == value[i]) {
						find = true;
						break;
					}
				}
				if (!find) {
					ptrsmap[sid].ptr_s.push_back(value[i]);
				}
			}
		}
	}
}
Example #2
0
int main(){
	char string[1000];
	printf("Enter the string: ");
	scanf("%s",string);
	if(regex1(string)){
		printf("String is of the form a(ab)+a \n");
	}
	else{
		printf("String is not of the form a(ab)+a\n");
	}
	return 0;
}
Example #3
0
pgsRecord pgsString::record() const
{
	pgsRecord *rec = 0;

	// Try to find the representation of a record in the string
	{
		wxString element(wxT("(\"([^\"\\\\]|\\\\.)*\")|((-|[a-zA-Z0-9\\+\\.])+)"));
		wxString data(m_data);
		wxRegEx regex1(wxString() << wxT("^[[:space:]]*\\([[:space:]]*(")
		               << element << wxT(")[[:space:]]*([,][[:space:]]*(")
		               << element << wxT(")[[:space:]]*)*\\)"), wxRE_DEFAULT | wxRE_ICASE);

		// Find each line
		size_t line_nb = 0, nb_of_columns = 0;
		bool count_columns = true;
		while (regex1.Matches(data))
		{
			// Process that line: find each element
			wxString line(regex1.GetMatch(data));
			wxRegEx regex2(element);
			size_t column_nb = 0;
			while (regex2.Matches(line))
			{
				if (count_columns == true)
				{
					++nb_of_columns;
				}
				else
				{
					if (column_nb < nb_of_columns && rec != 0)
					{
						wxString value(regex2.GetMatch(line));
						if (value.StartsWith(wxT("\""))
						        && value.EndsWith(wxT("\"")))
						{
							// This is a string
							value = value.Mid(1, value.Len() - 2);
							value.Replace(wxT("\\\""), wxT("\""));
							value.Replace(wxT("\\\\"), wxT("\\"));
							rec->insert(line_nb, column_nb,
							            pnew pgsString(value));
						}
						else
						{
							// This is a number or a string
							pgsTypes type = pgsNumber::num_type(value);
							switch (type)
							{
								case pgsTInt:
									rec->insert(line_nb, column_nb,
									            pnew pgsNumber(value, pgsInt));
									break;
								case pgsTReal:
									rec->insert(line_nb, column_nb,
									            pnew pgsNumber(value, pgsReal));
									break;
								default:
									rec->insert(line_nb, column_nb,
									            pnew pgsString(value));
									break;
							}
						}
					}
					++column_nb;
				}

				regex2.ReplaceFirst(&line, wxT(""));
			}

			// If it is the first loop we want to process this line a
			// second time because the first one was meant to count
			// the number of columns
			if (count_columns == true)
			{
				count_columns = false;
				rec = pnew pgsRecord(nb_of_columns);
			}
			else
			{
				regex1.ReplaceFirst(&data, wxT(""));
				++line_nb;
			}
		}
	}

	// Process the case
	if (rec == 0)
	{
		rec = pnew pgsRecord(1);
		rec->insert(0, 0, this->clone());
	}

	pgsRecord ret_val(*rec);
	pdelete(rec);
	return ret_val;
}