<commit_before>#include "slre.h"
#include <string.h>
#include <stdbool.h>
#include "rest.h"
#include <string>
#include <utility>

namespace ouroboros
{
	static const char * full_regex = "^/groups/([a-z0-9-_]+)/fields/([a-z0-9-_]+)/?$";
	static const char * group_regex = "^/groups/([a-z0-9-_]+)/?$";

	bool is_REST_URI(const std::string& aURI)
	{
		int result =
			slre_match(full_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		int group_result =
			slre_match(group_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);

		return (result >= 0 || group_result >= 0);
	}

	REST_call_type get_REST_call_type(const std::string& aURI)
	{	
		int item_result = slre_match(
			full_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		if (item_result >= 0)
			return REST_call_type::NAME;
		
		int group_result = slre_match(
			group_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		if (group_result >= 0)
			return REST_call_type::GROUP;
		
		return REST_call_type::NONE;
	}

	HTTP_request_type get_HTTP_request_type(const std::string& aMethodType)
	{
		if (aMethodType == "PUT")
		{
			return HTTP_request_type::PUT;
		}
		else if (aMethodType == "POST")
		{
			return HTTP_request_type::POST;
		}
		else if (aMethodType == "GET")
		{
			return HTTP_request_type::GET;
		}
		else if (aMethodType == "DELETE")
		{
			return HTTP_request_type::DELETE;
		}
		return HTTP_request_type::UNKNOWN;
	}

	std::pair<std::string, std::string> extract_group_name(const std::string& aURI)
	{
		struct slre_cap match[2];
		slre_match(full_regex, aURI.c_str(), aURI.length(), match, 2, 0);

		std::pair<std::string, std::string> result;
		
		//Copy group title from match to remove remaining characters
		std::string groupTitle(match[0].ptr);
		groupTitle.erase(groupTitle.begin()+match[0].len, groupTitle.end());

		result.first.assign(groupTitle);
		result.second.assign(match[1].ptr, match[1].len);
		return result;
	}
<commit_msg>Modified the REST api to accept root fields without having to specify that they are in the root group (server).<commit_after>#include "slre.h"
#include <string.h>
#include <stdbool.h>
#include "rest.h"
#include <string>
#include <utility>

namespace ouroboros
{
	static const char * full_regex = "^/groups/([a-z0-9-_]+)/fields/([a-z0-9-_]+)/?$";
	static const char * group_regex = "^/groups/([a-z0-9-_]+)/?$";
	static const char * root_field_regex = "^/fields/([a-z0-9-_]+)/?$";

	bool is_REST_URI(const std::string& aURI)
	{
		int result =
			slre_match(full_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		int group_result =
			slre_match(group_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		int root_field_result =
			slre_match(root_field_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
	
		return (result >= 0 || group_result >= 0 || root_field_result >= 0);
	}

	REST_call_type get_REST_call_type(const std::string& aURI)
	{	
		int item_result = slre_match(
			full_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		int root_item_result = slre_match(
			root_field_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		if (item_result >= 0 || root_item_result >= 0)
			return REST_call_type::NAME;
		
		int group_result = slre_match(
			group_regex, aURI.c_str(), aURI.length(), NULL, 0, 0);
		if (group_result >= 0)
			return REST_call_type::GROUP;
		
		return REST_call_type::NONE;
	}

	HTTP_request_type get_HTTP_request_type(const std::string& aMethodType)
	{
		if (aMethodType == "PUT")
		{
			return HTTP_request_type::PUT;
		}
		else if (aMethodType == "POST")
		{
			return HTTP_request_type::POST;
		}
		else if (aMethodType == "GET")
		{
			return HTTP_request_type::GET;
		}
		else if (aMethodType == "DELETE")
		{
			return HTTP_request_type::DELETE;
		}
		return HTTP_request_type::UNKNOWN;
	}

	std::pair<std::string, std::string> extract_group_name(const std::string& aURI)
	{
		//Check if user is accessing field in root first
		struct slre_cap match[1];
		if(slre_match(root_field_regex, aURI.c_str(), aURI.length(), match, 1, 0)){
			std::pair<std::string, std::string> result;
			//Root group is "server"
			result.first.assign("server");
			result.second.assign(match[0].ptr, match[0].len);
			
			return result;
		}
		else{
			struct slre_cap match[2];
			slre_match(full_regex, aURI.c_str(), aURI.length(), match, 2, 0);

			std::pair<std::string, std::string> result;
			
			//Copy group title from match to remove remaining characters
			std::string groupTitle(match[0].ptr);
			groupTitle.erase(groupTitle.begin()+match[0].len, groupTitle.end());

			result.first.assign(groupTitle);
			result.second.assign(match[1].ptr, match[1].len);
			return result;
		}
	}

{'fraction_non_alphanumeric': 0.16175195143104942, 'fraction_numerical': 0.013660017346053772, 'mean_word_length': 4.382730455075846, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3471463', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1736, 'n_words': 370}