![]() |
![]() |
![]() |
[Insert name here] Reference Manual | |
---|---|---|---|---|
#define PK_DBUS_SERVICE #define PK_DBUS_PATH #define PK_DBUS_INTERFACE guint pk_strlen (gchar *text, guint max_length); gboolean pk_strzero (const gchar *text); gboolean pk_strvalidate (const gchar *text); gboolean pk_strequal (const gchar *id1, const gchar *id2); gboolean pk_strnumber (const gchar *text); gboolean pk_strtoint (const gchar *text, gint *value); gboolean pk_strtouint (const gchar *text, guint *value); gchar* pk_strpad (const gchar *data, guint length); gchar* pk_strpad_extra (const gchar *data, guint length, guint *extra); gchar* pk_strsafe (const gchar *text); gchar** pk_strsplit (const gchar *id, guint parts); gchar* pk_strbuild_va (const gchar *first_element, va_list *args); gboolean pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint match); gboolean pk_filter_check (const gchar *filter); gchar* pk_iso8601_present (void); guint pk_iso8601_difference (const gchar *isodate);
guint pk_strlen (gchar *text, guint max_length);
This function is a much safer way of doing strlen as it checks for NULL and a stupidly long string. This also modifies the string in place if it is over-range by inserting a NULL at the max_length.
|
The text to check |
|
The maximum length of the string |
Returns : |
the length of the string, or max_length. |
gboolean pk_strzero (const gchar *text);
This function is a much safer way of doing "if (strlen (text) == 0))" as it does not rely on text being NULL terminated. It's also much quicker as it only checks the first byte rather than scanning the whole string just to verify it's not zero length.
|
The text to check |
Returns : |
TRUE if the string was converted correctly
|
gboolean pk_strvalidate (const gchar *text);
Tests a string to see if it may be dangerous or invalid.
|
The text to check for validity |
Returns : |
TRUE if the string is valid
|
gboolean pk_strequal (const gchar *id1, const gchar *id2);
This function is a much safer way of doing strcmp as it checks for NULL first, and returns boolean TRUE, not zero for success.
gboolean pk_strnumber (const gchar *text);
Tests a string to see if it is a number. Both positive and negative numbers are allowed.
|
The text the validate |
Returns : |
TRUE if the string represents a numeric value
|
gboolean pk_strtoint (const gchar *text, gint *value);
Converts a string into a signed integer value in a safe way.
|
The text the convert |
|
The return numeric return value, or 0 if invalid. |
Returns : |
TRUE if the string was converted correctly
|
gboolean pk_strtouint (const gchar *text, guint *value);
Converts a string into a unsigned integer value in a safe way.
|
The text the convert |
|
The return numeric return value, or 0 if invalid. |
Returns : |
TRUE if the string was converted correctly
|
gchar* pk_strpad (const gchar *data, guint length);
Returns the text padded to a length with spaces. If the string is longer than length then a longer string is returned.
|
the input string |
|
the desired length of the output string, with padding |
Returns : |
The padded string |
gchar* pk_strpad_extra (const gchar *data, guint length, guint *extra);
This function pads a string, but allows a follow-on value. This is useful if the function is being used to print columns of text, and one oversize one has to be absorbed into the next where possible.
|
the input string |
|
the desired length of the output string, with padding |
|
if we are running with a deficit, we might have a positive offset |
Returns : |
The padded string |
gchar* pk_strsafe (const gchar *text);
Replaces chars in the text that may be dangerous, or that may print incorrectly. These chars include new lines, tabs and quotes, and are replaced by spaces.
|
The input text to make safe |
Returns : |
the new string with no insane chars |
gchar** pk_strsplit (const gchar *id, guint parts);
Splits a string into the correct number of parts, checking the correct number of delimiters are present.
|
the ; delimited string to split |
|
how many parts the delimted string should be split into |
Returns : |
a char array is split correctly, NULL if invalid
Note: You need to use g_strfreev on the returned value
|
gchar* pk_strbuild_va (const gchar *first_element, va_list *args);
This function converts a va_list into a string in a safe and efficient way, e.g. pk_strbuild_va("foo","bar","baz") == "foo bar baz"
|
The first string item, or NULL |
|
the va_list |
Returns : |
the single string |
gboolean pk_strcmp_sections (const gchar *id1, const gchar *id2, guint parts, guint match);
We only want to compare some first sections, not all the data when comparing package_id's and transaction_id's.
|
the first item of text to test |
|
the second item of text to test |
|
the number of parts each id should have |
|
|
Returns : |
TRUE if the strings can be considered the same.
|
gboolean pk_filter_check (const gchar *filter);
Tests a compound filter to see if every element is correct and if it well formed.
|
A text failter to test |
Returns : |
TRUE if the filter is valid
|