mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-19 14:19:36 +08:00
Add URL routines
This commit is contained in:
parent
06067d35b4
commit
fac71e0dcb
@ -3,18 +3,44 @@
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
* File Name : chef.h
|
* File Name : chef.h
|
||||||
* File Authors : Aoran Zeng <ccmywish@qq.com>
|
* File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||||
* Contributors : Peng Gao <gn3po4g@outlook.com>
|
* Contributors : Nul None <nul@none.org>
|
||||||
* Created On : <2025-07-14>
|
* Created On : <2025-07-14>
|
||||||
* Last Modified : <2025-07-14>
|
* Last Modified : <2025-07-14>
|
||||||
*
|
*
|
||||||
* For chefs (recipe makers) and sometimes framewoker
|
* For chefs (recipe makers) and sometimes framewoker
|
||||||
|
* to do some work not releated to OS operations
|
||||||
* ------------------------------------------------------------*/
|
* ------------------------------------------------------------*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_url (const char *str)
|
is_url (const char *str)
|
||||||
{
|
{
|
||||||
return (xy_str_start_with (str, "http://") || xy_str_start_with (str, "https://"));
|
return (xy_str_start_with (str, "http://") || xy_str_start_with (str, "https://"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 一律返回新字符串
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
chef_remove_trailing_slash (char *str)
|
||||||
|
{
|
||||||
|
char *newstr = xy_strdup (str);
|
||||||
|
size_t len = strlen (newstr);
|
||||||
|
if (len > 0 && newstr[len - 1] == '/')
|
||||||
|
newstr[len - 1] = '\0';
|
||||||
|
return newstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 一律返回新字符串
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
chef_ensure_trailing_slash (char *str)
|
||||||
|
{
|
||||||
|
size_t len = strlen (str);
|
||||||
|
if (len == 0 || str[len - 1] == '/')
|
||||||
|
return xy_strdup (str);
|
||||||
|
|
||||||
|
return xy_2strjoin (str, "/");
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user