319a63d22e9ad13550513b9a88fe7cb92a44de55
[occt.git] / src / Standard / Standard_CString.hxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 //!@file
16 //! Functions working with plain C strings
17
18 #ifndef _Standard_CString_HeaderFile
19 # define _Standard_CString_HeaderFile
20
21 #include <Standard_Macro.hxx>
22
23 # include <string.h>
24 # include <stdio.h>
25
26 # if defined(_MSC_VER) && ! defined(strcasecmp)
27 #  define strcasecmp _stricmp
28 # endif
29
30 // C++ only definitions
31 #ifdef __cplusplus
32
33 #include <Standard_Integer.hxx>
34
35 //! Returns bounded hash code for the null-terminated string, in the range [1, theUpperBound]
36 //! @param theString the null-terminated string which hash code is to be computed
37 //! @param theUpperBound the upper bound of the range a computing hash code must be within
38 //! @return a computed hash code, in the range [1, theUpperBound]
39 Standard_EXPORT Standard_Integer HashCode (Standard_CString theString, Standard_Integer theUpperBound);
40
41 //! Returns 32-bit hash code for the first theLen characters in the string theStr.
42 //! The result is unbound (may be not only positive, but also negative)
43 //! @param theString the string which hash code is to be computed
44 //! @param theLength the length of the given string
45 //! @return a computed hash code of the given string
46 Standard_EXPORT Standard_Integer HashCodes (Standard_CString theString, Standard_Integer theLength);
47
48 //! Returns bounded hash code for the first theLength characters in the string theString, in the range [1, theUpperBound]
49 //! @param theString the string which hash code is to be computed
50 //! @param theLength the length of the initial substring of the given string which hash code is to be computed
51 //! @param theUpperBound the upper bound of the range a computing hash code must be within
52 //! @return a computed hash code of the given string
53 inline Standard_Integer HashCode (const Standard_CString theString,
54                                   const Standard_Integer theLength,
55                                   const Standard_Integer theUpperBound)
56 {
57 //  return (Abs( HashCodes( Value , Len ) ) % Upper ) + 1 ;
58   return HashCode (HashCodes (theString, theLength), theUpperBound);
59 }
60
61 //! Returns Standard_True if two strings are equal
62 inline Standard_Boolean IsEqual (const Standard_CString theOne, const Standard_CString theTwo)
63 {
64   return strcmp (theOne, theTwo) == 0;
65 }
66
67 #endif /* __cplusplus */
68
69 #ifdef __cplusplus
70 extern "C" {
71 #endif /* __cplusplus */
72
73 //! Equivalent of standard C function atof() that always uses C locale
74 Standard_EXPORT double Atof (const char* theStr);
75
76 //! Optimized equivalent of standard C function strtod() that always uses C locale
77 Standard_EXPORT double Strtod (const char* theStr, char** theNextPtr);
78
79 //! Equivalent of standard C function printf() that always uses C locale
80 Standard_EXPORT int Printf (const char* theFormat, ...);
81
82 //! Equivalent of standard C function fprintf() that always uses C locale
83 Standard_EXPORT int Fprintf (FILE* theFile, const char* theFormat, ...);
84
85 //! Equivalent of standard C function sprintf() that always uses C locale
86 Standard_EXPORT int Sprintf (char* theBuffer, const char* theFormat, ...);
87
88 #ifdef __cplusplus
89 }
90 #endif /* __cplusplus */
91
92 #endif