2003-12-31 11:33:02 +01:00
|
|
|
/*
|
2004-07-10 05:17:02 +02:00
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Claudio Valderrama on 25-Dec-2003
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Claudio Valderrama
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2003-12-31 11:33:02 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// =====================================
|
|
|
|
// Utility functions
|
|
|
|
|
2004-01-03 15:12:45 +01:00
|
|
|
|
2004-01-13 14:40:20 +01:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#else
|
2004-01-03 15:12:45 +01:00
|
|
|
#define __need_size_t
|
|
|
|
#include <stddef.h>
|
|
|
|
#undef __need_size_t
|
|
|
|
#endif
|
|
|
|
|
2004-03-31 20:10:22 +02:00
|
|
|
#include "../common/utils_proto.h"
|
|
|
|
|
2004-09-15 05:49:52 +02:00
|
|
|
namespace fb_utils
|
|
|
|
{
|
2003-12-31 11:33:02 +01:00
|
|
|
|
|
|
|
char* fb_exact_name(char* const str)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* f b _ e x a c t _ n a m e
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Trim off trailing spaces from a metadata name.
|
|
|
|
* eg: insert a null after the last non-blank character.
|
|
|
|
*
|
|
|
|
* SQL delimited identifier may have blank as part of the name
|
|
|
|
*
|
|
|
|
* Parameters: str - the string to terminate
|
|
|
|
* Returns: str
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
char* p = str;
|
|
|
|
while (*p)
|
|
|
|
++p;
|
|
|
|
// Now, let's go back
|
|
|
|
--p;
|
|
|
|
while (p >= str && *p == '\x20') // blank character, ASCII(32)
|
|
|
|
--p;
|
|
|
|
*(p + 1) = '\0';
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2004-09-15 05:49:52 +02:00
|
|
|
|
2003-12-31 11:33:02 +01:00
|
|
|
char* fb_exact_name_limit(char* const str, size_t bufsize)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* f b _ e x a c t _ n a m e _ l i m i t
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Trim off trailing spaces from a metadata name.
|
|
|
|
* eg: insert a null after the last non-blank character.
|
|
|
|
* It has a maximum length to ensure working between bounds.
|
|
|
|
*
|
|
|
|
* SQL delimited identifier may have blank as part of the name
|
|
|
|
*
|
|
|
|
* Parameters: str - the string to terminate
|
|
|
|
* Returns: str
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
const char* const end = str + bufsize - 1;
|
|
|
|
char* p = str;
|
|
|
|
while (*p && p < end)
|
|
|
|
++p;
|
|
|
|
// Now, let's go back
|
|
|
|
--p;
|
|
|
|
while (p >= str && *p == '\x20') // blank character, ASCII(32)
|
|
|
|
--p;
|
|
|
|
*(p + 1) = '\0';
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2004-09-15 05:49:52 +02:00
|
|
|
|
|
|
|
USHORT name_length(const TEXT* const name)
|
|
|
|
{
|
|
|
|
/**************************************
|
|
|
|
*
|
|
|
|
* n a m e _ l e n g t h
|
|
|
|
*
|
|
|
|
**************************************
|
|
|
|
*
|
|
|
|
* Functional description
|
|
|
|
* Compute effective length of system relation name and others.
|
|
|
|
* SQL delimited identifier may contain blanks. Trailing blanks are ignored.
|
|
|
|
* Assumes input is null terminated.
|
|
|
|
*
|
|
|
|
**************************************/
|
|
|
|
const TEXT* q = name - 1;
|
|
|
|
for (const TEXT* p = name; *p; p++) {
|
|
|
|
if (*p != ' ') {
|
|
|
|
q = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (q + 1) - name;
|
|
|
|
}
|
|
|
|
|
2003-12-31 11:33:02 +01:00
|
|
|
} // namespace fb_utils
|
|
|
|
|
|
|
|
|