Vault  4.1
vchar.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved.
00003 This file is part of the Code Vault version 4.1
00004 http://www.bombaydigital.com/
00005 License: MIT. See LICENSE.md in the Vault top level directory.
00006 */
00007 
00010 #include "vchar.h"
00011 
00012 /*
00013 The "null character" constant constructs to char value zero.
00014 This is used by VString to return a null char when an accessor
00015 reads the zero byte of an empty string.
00016 */
00017 // static
00018 const VChar& VChar::NULL_CHAR() {
00019     static const VChar kNullChar;
00020     return kNullChar;
00021 }
00022 
00023 VChar::VChar()
00024     : mValue(VCHAR_NULL_TERMINATOR)
00025     {
00026 }
00027 
00028 VChar::VChar(char c)
00029     : mValue(c)
00030     {
00031 }
00032 
00033 VChar::VChar(int i)
00034     : mValue(static_cast<char>(i))
00035     {
00036 }
00037 
00038 VChar& VChar::operator=(char c) {
00039     mValue = c;
00040     return *this;
00041 }
00042 
00043 VChar& VChar::operator=(int i) {
00044     mValue = static_cast<char>(i);
00045     return *this;
00046 }
00047 
00048 // Note: Use of static_cast<Vu8> here is to force to positive int before calling int-based library APIs.
00049 // Alternative would be to call this->intValue(), but that might incur one extra copy of the char.
00050 
00051 bool VChar::isLowerCase() const {
00052     return (islower(static_cast<Vu8>(mValue)) != 0);    // Note: global scope operator removed to compile against HPUX headers which use a macro
00053 }
00054 
00055 VChar VChar::lowerCase() const {
00056     return VChar(::tolower(static_cast<Vu8>(mValue)));
00057 }
00058 
00059 void VChar::toLowerCase() {
00060     mValue = static_cast<char>(::tolower(static_cast<Vu8>(mValue)));
00061 }
00062 
00063 bool VChar::isUpperCase() const {
00064     return (isupper(static_cast<Vu8>(mValue)) != 0);    // Note: global scope operator removed to compile against HPUX headers which use a macro
00065 }
00066 
00067 VChar VChar::upperCase() const {
00068     return VChar(::toupper(static_cast<Vu8>(mValue)));
00069 }
00070 
00071 void VChar::toUpperCase() {
00072     mValue = static_cast<char>(::toupper(static_cast<Vu8>(mValue)));
00073 }
00074 
00075 char VChar::charValue() const {
00076     return mValue;
00077 }
00078 
00079 int VChar::intValue() const {
00080     // Need to make sure return value is positive even for mValue > 0x7F.
00081     Vu8 unsignedValue = static_cast<Vu8>(mValue);
00082     return unsignedValue;
00083 }
00084 
00085 void VChar::set(char c) {
00086     mValue = c;
00087 }
00088 
00089 void VChar::set(int i) {
00090     mValue = static_cast<char>(i);
00091 }
00092 
00093 VChar::operator char() const {
00094     return mValue;
00095 }
00096 
00097 bool VChar::isAlpha() const {
00098     return ((mValue >= 'a') && (mValue <= 'z')) ||
00099            ((mValue >= 'A') && (mValue <= 'Z'));
00100 }
00101 
00102 bool VChar::isNumeric() const {
00103     return (mValue >= '0') && (mValue <= '9');
00104 }
00105 
00106 bool VChar::isAlphaNumeric() const {
00107     return this->isAlpha() || this->isNumeric();
00108 }
00109 
00110 bool VChar::isWhitespace() const {
00111     // Need to be careful about signage for values > 0x7F.
00112     int value = this->intValue();
00113     return (value <= 0x20) || (value == 0x7F);
00114 }
00115 
00116 bool VChar::isHexadecimal() const {
00117     return ((mValue >= '0') && (mValue <= '9')) ||
00118            ((mValue >= 'a') && (mValue <= 'f')) ||
00119            ((mValue >= 'A') && (mValue <= 'F'));
00120 }
00121 
00122 // static
00123 bool VChar::equalsIgnoreCase(const VChar& c1, const VChar& c2) {
00124     return (c1 == c2) ||
00125            (c1.upperCase() == c2) ||
00126            (c2.upperCase() == c1);
00127 }
00128 
00129 // static
00130 bool VChar::equalsIgnoreCase(const VChar& c1, char c2) {
00131     return VChar::equalsIgnoreCase(c1, VChar(c2));
00132 }
00133 
00134 // static
00135 bool VChar::equalsIgnoreCase(char c1, const VChar& c2) {
00136     return VChar::equalsIgnoreCase(VChar(c1), c2);
00137 }
00138 
00139 // static
00140 bool VChar::equalsIgnoreCase(char c1, char c2) {
00141     return VChar::equalsIgnoreCase(VChar(c1), VChar(c2));
00142 }
00143 

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.