mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Get trim() out of core where it is not needed.
This commit is contained in:
parent
53e5f94b99
commit
a7409850d6
3 changed files with 20 additions and 28 deletions
|
@ -261,25 +261,6 @@ std::vector<std::string> Utils::split(const char *s,const char *const sep,const
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Utils::trim(const std::string &s)
|
|
||||||
{
|
|
||||||
unsigned long end = (unsigned long)s.length();
|
|
||||||
while (end) {
|
|
||||||
char c = s[end - 1];
|
|
||||||
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
|
|
||||||
--end;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
unsigned long start = 0;
|
|
||||||
while (start < end) {
|
|
||||||
char c = s[start];
|
|
||||||
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
|
|
||||||
++start;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
return s.substr(start,end - start);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int Utils::snprintf(char *buf,unsigned int len,const char *fmt,...)
|
unsigned int Utils::snprintf(char *buf,unsigned int len,const char *fmt,...)
|
||||||
throw(std::length_error)
|
throw(std::length_error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -256,14 +256,6 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Trim whitespace from the start and end of a string
|
|
||||||
*
|
|
||||||
* @param s String to trim
|
|
||||||
* @return Trimmed string
|
|
||||||
*/
|
|
||||||
static std::string trim(const std::string &s);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variant of snprintf that is portable and throws an exception
|
* Variant of snprintf that is portable and throws an exception
|
||||||
*
|
*
|
||||||
|
|
|
@ -338,6 +338,25 @@ public:
|
||||||
static BackgroundSoftwareUpdateChecker backgroundSoftwareUpdateChecker;
|
static BackgroundSoftwareUpdateChecker backgroundSoftwareUpdateChecker;
|
||||||
#endif // ZT_AUTO_UPDATE
|
#endif // ZT_AUTO_UPDATE
|
||||||
|
|
||||||
|
static std::string _trimString(const std::string &s)
|
||||||
|
{
|
||||||
|
unsigned long end = (unsigned long)s.length();
|
||||||
|
while (end) {
|
||||||
|
char c = s[end - 1];
|
||||||
|
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
|
||||||
|
--end;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
unsigned long start = 0;
|
||||||
|
while (start < end) {
|
||||||
|
char c = s[start];
|
||||||
|
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
|
||||||
|
++start;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
return s.substr(start,end - start);
|
||||||
|
}
|
||||||
|
|
||||||
class OneServiceImpl;
|
class OneServiceImpl;
|
||||||
|
|
||||||
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf);
|
static int SnodeVirtualNetworkConfigFunction(ZT_Node *node,void *uptr,uint64_t nwid,enum ZT_VirtualNetworkConfigOperation op,const ZT_VirtualNetworkConfig *nwconf);
|
||||||
|
@ -521,7 +540,7 @@ public:
|
||||||
} else OSUtils::lockDownFile(authTokenPath.c_str(),false);
|
} else OSUtils::lockDownFile(authTokenPath.c_str(),false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
authToken = Utils::trim(authToken);
|
authToken = _trimString(authToken);
|
||||||
|
|
||||||
_node = new Node(
|
_node = new Node(
|
||||||
OSUtils::now(),
|
OSUtils::now(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue