2015-01-03 20:51:52 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* string.c
|
|
|
|
* string handling helpers
|
|
|
|
*
|
|
|
|
*
|
2018-01-03 05:30:12 +01:00
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
2015-01-03 20:51:52 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/common/string.c
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FRONTEND
|
|
|
|
#include "postgres.h"
|
|
|
|
#else
|
|
|
|
#include "postgres_fe.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common/string.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns whether the string `str' has the postfix `end'.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
pg_str_endswith(const char *str, const char *end)
|
|
|
|
{
|
|
|
|
size_t slen = strlen(str);
|
|
|
|
size_t elen = strlen(end);
|
|
|
|
|
|
|
|
/* can't be a postfix if longer */
|
|
|
|
if (elen > slen)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* compare the end of the strings */
|
|
|
|
str += slen - elen;
|
|
|
|
return strcmp(str, end) == 0;
|
|
|
|
}
|
2018-03-13 15:21:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* strtoint --- just like strtol, but returns int not long
|
|
|
|
*/
|
|
|
|
int
|
2018-03-15 14:02:51 +01:00
|
|
|
strtoint(const char *pg_restrict str, char **pg_restrict endptr, int base)
|
2018-03-13 15:21:09 +01:00
|
|
|
{
|
|
|
|
long val;
|
|
|
|
|
|
|
|
val = strtol(str, endptr, base);
|
|
|
|
if (val != (int) val)
|
|
|
|
errno = ERANGE;
|
|
|
|
return (int) val;
|
|
|
|
}
|