Agents 1.5.0
Edge AI Agents SDK
Loading...
Searching...
No Matches
agents::Utils Class Reference

Utility class providing static helper functions. More...

#include <utils.h>

Static Public Member Functions

static void changeKey (JsonObject &object, const std::string &old_key, const std::string &new_key)
 Change a key in a JSON object.
static std::string toLower (const std::string &s)
 Convert a string to lowercase.
static std::string toUpper (const std::string &s)
 Convert a string to uppercase.
static std::vector< std::string > splitByNewline (const std::string &text)
 Split a string by newlines.
static void trim (std::string &s)
 String trim helper.
static std::string getBaseUrl (const std::string &url)
 Extract the path (including leading '/') from a full URL.
static std::string getPathFromUrl (const std::string &url)
 Extract the path (including leading '/') from a full URL.
static std::string getHostFromUrl (const std::string &url)
 Get the hostname From Url object.
static int getPortFromUrl (const std::string &url)
 Get the port from a URL string.
static std::string loadHtmlFile (const std::string &filename)
 Load an HTML file from disk.
static std::string stripHtmlTags (const std::string &html, size_t max_length=0)
 Strip HTML tags from a string, producing plain text.
static std::string extractHtmlTagContent (const std::string &html, const std::string &tag)
 Extract the text content of the first occurrence of a given HTML tag.

Detailed Description

Utility class providing static helper functions.

Member Function Documentation

◆ changeKey()

void agents::Utils::changeKey ( JsonObject & object,
const std::string & old_key,
const std::string & new_key )
inlinestatic

Change a key in a JSON object.

Parameters
objectThe JSON object
old_keyThe old key name
new_keyThe new key name

◆ extractHtmlTagContent()

std::string agents::Utils::extractHtmlTagContent ( const std::string & html,
const std::string & tag )
inlinestatic

Extract the text content of the first occurrence of a given HTML tag.

Parameters
htmlThe HTML string to search
tagThe tag name to find (e.g., "title")
Returns
The text content within the first matching tag, or empty string if not found

◆ getBaseUrl()

std::string agents::Utils::getBaseUrl ( const std::string & url)
inlinestatic

Extract the path (including leading '/') from a full URL.

Example: https://example.com/api/search?q=x -> /api/search?q=x

Parameters
urlFull URL
Returns
std::string Path and query portion

◆ getHostFromUrl()

std::string agents::Utils::getHostFromUrl ( const std::string & url)
inlinestatic

Get the hostname From Url object.

(e.g., "127.0.0.1") stripping "http://" and ":8080"

Parameters
urlThe URL string
Returns
std::string The hostname portion of the URL

◆ getPathFromUrl()

std::string agents::Utils::getPathFromUrl ( const std::string & url)
inlinestatic

Extract the path (including leading '/') from a full URL.

Example: https://example.com/api/search?q=x -> /api/search?q=x

Parameters
urlFull URL
Returns
std::string Path and query portion

◆ getPortFromUrl()

int agents::Utils::getPortFromUrl ( const std::string & url)
inlinestatic

Get the port from a URL string.

Returns the port as an integer (defaulting to 80 or 443 if not found)

Parameters
urlThe URL string
Returns
int The port number

◆ loadHtmlFile()

std::string agents::Utils::loadHtmlFile ( const std::string & filename)
inlinestatic

Load an HTML file from disk.

Parameters
filenameThe path to the HTML file
Returns
The file contents as a string

◆ splitByNewline()

std::vector< std::string > agents::Utils::splitByNewline ( const std::string & text)
inlinestatic

Split a string by newlines.

Parameters
textThe text to split
Returns
The lines

◆ stripHtmlTags()

std::string agents::Utils::stripHtmlTags ( const std::string & html,
size_t max_length = 0 )
inlinestatic

Strip HTML tags from a string, producing plain text.

Removes script/style/nav/header/footer/noscript blocks entirely, strips remaining tags, decodes common HTML entities, and collapses whitespace.

Parameters
htmlThe HTML string to strip
max_lengthMaximum output length (0 = unlimited). Truncates at word boundary.
Returns
Plain text extracted from the HTML

◆ toLower()

std::string agents::Utils::toLower ( const std::string & s)
inlinestatic

Convert a string to lowercase.

Parameters
sThe input string
Returns
The lowercase string

◆ toUpper()

std::string agents::Utils::toUpper ( const std::string & s)
inlinestatic

Convert a string to uppercase.

Parameters
sThe input string
Returns
std::string

◆ trim()

void agents::Utils::trim ( std::string & s)
inlinestatic

String trim helper.

Parameters
sthe input string