version 1.26, 2004/06/15 18:38:24
|
version 1.35, 2007/02/13 19:21:44
|
|
|
//%2003//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L. P., IBM Corp., The Open Group, Tivoli Systems. |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; | // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; |
// IBM Corp.; EMC Corporation, The Open Group. | // IBM Corp.; EMC Corporation, The Open Group. |
|
// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; |
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
|
// |
|
// Modified By: Roger Kumpf, Hewlett Packard Company (roger_kumpf@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <cctype> | #include <cctype> |
#include "CIMName.h" | #include "CIMName.h" |
#include "CommonUTF.h" | #include "CommonUTF.h" |
|
#include "CharSet.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
# include "ArrayImpl.h" | # include "ArrayImpl.h" |
#undef PEGASUS_ARRAY_T | #undef PEGASUS_ARRAY_T |
| |
CIMName::CIMName() |
CIMName::CIMName(const String& name) : cimName(name) |
: cimName(String::EMPTY) |
|
{ | { |
|
if (!legal(name)) |
|
throw InvalidNameException(name); |
} | } |
| |
CIMName::CIMName(const String& name) |
CIMName::CIMName(const char* name) : cimName(name) |
: cimName(name) |
|
{ | { |
if (!legal(name)) | if (!legal(name)) |
{ |
|
throw InvalidNameException(name); | throw InvalidNameException(name); |
} | } |
} |
|
| |
CIMName::CIMName(const char* name) |
CIMName& CIMName::operator=(const String& name) |
: cimName(name) |
|
{ | { |
if (!legal(name)) | if (!legal(name)) |
{ |
|
throw InvalidNameException(name); | throw InvalidNameException(name); |
} |
|
} |
|
| |
CIMName& CIMName::operator=(const CIMName& name) |
cimName=name; |
{ |
|
cimName=name.cimName; |
|
return *this; | return *this; |
} | } |
| |
CIMName& CIMName::operator=(const String& name) |
CIMName& CIMName::operator=(const char* name) |
{ | { |
if (!legal(name)) | if (!legal(name)) |
{ |
|
throw InvalidNameException(name); | throw InvalidNameException(name); |
} |
|
cimName=name; | cimName=name; |
return *this; | return *this; |
} | } |
| |
const String& CIMName::getString() const |
Boolean CIMName::legal(const String& name) |
{ | { |
return cimName; |
// Check first character. |
} |
|
| |
Boolean CIMName::isNull() const |
const Uint16* p = (const Uint16*)name.getChar16Data(); |
{ |
Uint32 n = name.size(); |
return (cimName.size() == 0); |
|
} |
|
| |
void CIMName::clear() |
if (!(*p < 128 && CharSet::isAlphaUnder(*p))) |
{ | { |
cimName.clear(); |
if (!(*p >= 0x0080 && *p <= 0xFFEF)) |
|
return false; |
} | } |
| |
Boolean CIMName::legal(const String& name) |
p++; |
{ |
n--; |
Uint32 length = name.size(); |
|
Uint16 chkchr; |
|
| |
if (length == 0) |
// Use loop unrolling to skip over good ASCII 7-bit characters. |
return false; |
|
|
|
chkchr = name[0]; |
|
| |
// First character must be alphabetic or '_' if ASCII |
while (n >= 4) |
if(!( |
|
(chkchr == 0x005F) || |
|
((chkchr >= 0x0041) && (chkchr <= 0x005A)) || |
|
((chkchr >= 0x0061) && (chkchr <= 0x007A)) || |
|
((chkchr >= 0x0080) && (chkchr <= 0xFFEF)))) |
|
{ | { |
return false; |
if (p[0] < 128 && CharSet::isAlNumUnder(p[0]) && |
|
p[1] < 128 && CharSet::isAlNumUnder(p[1]) && |
|
p[2] < 128 && CharSet::isAlNumUnder(p[2]) && |
|
p[3] < 128 && CharSet::isAlNumUnder(p[3])) |
|
{ |
|
p += 4; |
|
n -= 4; |
|
continue; |
} | } |
| |
// Remaining characters must be alphanumeric or '_' if ASCII |
break; |
for(Uint32 i = 1; i < length; ++i) |
} |
|
|
|
// Process remaining charcters. |
|
|
|
while (n) |
{ | { |
chkchr = name[i]; |
if (!(*p < 128 && CharSet::isAlNumUnder(*p))) |
if(!( |
|
(chkchr == 0x005F) || |
|
((chkchr >= 0x0041) && (chkchr <= 0x005A)) || |
|
((chkchr >= 0x0061) && (chkchr <= 0x007A)) || |
|
((chkchr >= 0x0080) && (chkchr <= 0xFFEF)) || |
|
((chkchr >= 0x0030) && (chkchr <= 0x0039)))) |
|
{ | { |
|
if (!(*p >= 0x0080 && *p <= 0xFFEF)) |
return false; | return false; |
} | } |
|
p++; |
|
n--; |
} | } |
| |
return true; | return true; |
} | } |
| |
Boolean CIMName::equal(const CIMName& name) const |
|
{ |
|
return String::equalNoCase(cimName, name.cimName); |
|
} |
|
|
|
Boolean operator==(const CIMName& name1, const CIMName& name2) |
|
{ |
|
return name1.equal(name2); |
|
} |
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
// | // |
// CIMNamespaceName | // CIMNamespaceName |
|
|
# include "ArrayImpl.h" | # include "ArrayImpl.h" |
#undef PEGASUS_ARRAY_T | #undef PEGASUS_ARRAY_T |
| |
CIMNamespaceName::CIMNamespaceName() |
inline void _check_namespace_name(String& name) |
: cimNamespaceName(String::EMPTY) |
|
{ | { |
|
if (!CIMNamespaceName::legal(name)) |
|
throw InvalidNamespaceNameException(name); |
|
|
|
if (name[0] == '/') |
|
name.remove(0, 1); |
} | } |
| |
CIMNamespaceName::CIMNamespaceName(const String& name) | CIMNamespaceName::CIMNamespaceName(const String& name) |
|
: cimNamespaceName(name) |
{ | { |
*this = name; |
_check_namespace_name(cimNamespaceName); |
} | } |
| |
CIMNamespaceName::CIMNamespaceName(const char* name) | CIMNamespaceName::CIMNamespaceName(const char* name) |
|
: cimNamespaceName(name) |
{ | { |
*this = String(name); |
_check_namespace_name(cimNamespaceName); |
} | } |
| |
CIMNamespaceName& CIMNamespaceName::operator=(const CIMNamespaceName& name) | CIMNamespaceName& CIMNamespaceName::operator=(const CIMNamespaceName& name) |
|
|
| |
CIMNamespaceName& CIMNamespaceName::operator=(const String& name) | CIMNamespaceName& CIMNamespaceName::operator=(const String& name) |
{ | { |
if (!legal(name)) |
|
{ |
|
throw InvalidNamespaceNameException(name); |
|
} |
|
|
|
if (name[0] == '/') |
|
{ |
|
// Strip off the meaningless leading '/' |
|
cimNamespaceName=name.subString(1); |
|
} |
|
else |
|
{ |
|
cimNamespaceName=name; | cimNamespaceName=name; |
} |
_check_namespace_name(cimNamespaceName); |
|
|
return *this; | return *this; |
} | } |
| |
const String& CIMNamespaceName::getString() const |
CIMNamespaceName& CIMNamespaceName::operator=(const char* name) |
{ |
|
return cimNamespaceName; |
|
} |
|
|
|
Boolean CIMNamespaceName::isNull() const |
|
{ | { |
return (cimNamespaceName.size() == 0); |
cimNamespaceName = name; |
} |
_check_namespace_name(cimNamespaceName); |
|
return *this; |
void CIMNamespaceName::clear() |
|
{ |
|
cimNamespaceName.clear(); |
|
} | } |
| |
Boolean CIMNamespaceName::legal(const String& name) | Boolean CIMNamespaceName::legal(const String& name) |
|
|
return false; | return false; |
} | } |
| |
Uint16 chkchr = name[index++]; |
Uint16 ch = name[index++]; |
| |
// First character must be alphabetic or '_' if ASCII | // First character must be alphabetic or '_' if ASCII |
if(!( |
|
(chkchr == 0x005F) || |
if (!(ch < 128 && CharSet::isAlphaUnder(ch))) |
((chkchr >= 0x0041) && (chkchr <= 0x005A)) || |
|
((chkchr >= 0x0061) && (chkchr <= 0x007A)) || |
|
((chkchr >= 0x0080) && (chkchr <= 0xFFEF)))) |
|
{ | { |
|
if (!(ch >= 0x0080 && ch <= 0xFFEF)) |
return false; | return false; |
} | } |
| |
// Remaining characters must be alphanumeric or '_' if ASCII | // Remaining characters must be alphanumeric or '_' if ASCII |
while (index < length) | while (index < length) |
{ | { |
chkchr = name[index++]; |
ch = name[index++]; |
| |
// A '/' indicates another namespace element follows | // A '/' indicates another namespace element follows |
if (chkchr == '/') |
if (ch == '/') |
{ | { |
moreElements = true; | moreElements = true; |
break; | break; |
} | } |
| |
if(!( |
if (!(ch < 128 && CharSet::isAlNumUnder(ch))) |
(chkchr == 0x005F) || |
|
((chkchr >= 0x0041) && (chkchr <= 0x005A)) || |
|
((chkchr >= 0x0061) && (chkchr <= 0x007A)) || |
|
((chkchr >= 0x0080) && (chkchr <= 0xFFEF)) || |
|
((chkchr >= 0x0030) && (chkchr <= 0x0039)))) |
|
{ | { |
|
if (!(ch >= 0x0080 && ch <= 0xFFEF)) |
return false; | return false; |
} | } |
} | } |
|
|
return true; | return true; |
} | } |
| |
Boolean CIMNamespaceName::equal(const CIMNamespaceName& name) const |
Boolean operator==(const CIMNamespaceName& name1, const CIMNamespaceName& name2) |
{ | { |
return String::equalNoCase(cimNamespaceName, name.cimNamespaceName); |
return name1.equal(name2); |
} | } |
| |
Boolean operator==(const CIMNamespaceName& name1, const CIMNamespaceName& name2) |
Boolean operator==(const CIMNamespaceName& name1, const char* name2) |
{ | { |
return name1.equal(name2); | return name1.equal(name2); |
} | } |
| |
|
Boolean operator==(const char* name1, const CIMNamespaceName& name2) |
|
{ |
|
return name2.equal(name1); |
|
} |
|
|
|
Boolean operator!=(const CIMNamespaceName& name1, const CIMNamespaceName& name2) |
|
{ |
|
return !name1.equal(name2); |
|
} |
|
|
|
Boolean operator!=(const CIMNamespaceName& name1, const char* name2) |
|
{ |
|
return !name1.equal(name2); |
|
} |
|
|
|
Boolean operator!=(const char* name1, const CIMNamespaceName& name2) |
|
{ |
|
return !name2.equal(name1); |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
|
|
|
/* |
|
================================================================================ |
|
|
|
Optimizations: |
|
|
|
1. Optimized legal(). |
|
2. Implmented "char*" version of operator=(). |
|
3. Added conditional inlining (for Pegaus internal use). |
|
4. Added comparison functions for "char*". |
|
5. Implemented "unchecked" version of constructors and assignment operators |
|
that take String or "char*". |
|
6. Added loop unrolling to CIMName::legal() |
|
|
|
================================================================================ |
|
*/ |