// Copyright 2004 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // p4wI18n: // Utility methods providing Unicode-safe string operations #include <p4wp4.h> #include "p4wI18n.h" char *p4wI18n::safeStrrchr( char *str, char c ) { // // Returns pointer to the last instance of // character c. Traversal of this string // is unicode-safe, provided that the character // is one byte. char *ret = NULL; // // If we are not using a unicode character set, use // strrchr instead. if( GlobalCharSet::Get() == 0 ) return strrchr( str, c ); CharStep *s = CharStep::Create( str, GlobalCharSet::Get() ); for( char *ep = str + strlen( str ); s->Ptr() < ep; s->Next() ) { if( *s->Ptr() == c ) ret = s->Ptr(); } delete s; return ret; } int p4wI18n::safeStrrchrPos( char *str, char c ) { // // Returns byte-position of the last instance of // character c. Traversal of this string // is unicode-safe, provided that the character is // one byte. int ret = -1; char *p = NULL; // // If we are not using a unicode character set, // use strrchr instead. if( GlobalCharSet::Get() == 0 ) return ( strrchr( str, c ) - str ); CharStep *s = CharStep::Create( str, GlobalCharSet::Get() ); for( char *ep = str + strlen( str ); s->Ptr() < ep; s->Next() ) { if( *s->Ptr() == c ) p = s->Ptr(); } if( p ) ret = p - str; delete s; return ret; } char *p4wI18n::safeStrchr( char *str, char c ) { // // Returns pointer to the first instance of // character c. Traversal of this string // is unicode-safe, provided that the character // is one byte. char *ret = NULL; // // If we are not using a unicode character set, // use strchr instead. if( GlobalCharSet::Get() == 0 ) return strchr( str, c ); CharStep *s = CharStep::Create( str, GlobalCharSet::Get() ); for( char *ep = str + strlen( str ); s->Ptr() < ep; s->Next() ) { if( *s->Ptr() == c ) { ret = s->Ptr(); break; } } delete s; return ret; } int p4wI18n::safeStrchrPos( char *str, char c ) { // // Returns byte-position of the first instance of // character c. Traversal of this string // is unicode-safe, provided that the character // is one byte. int ret = -1; char *p = NULL; // // If we are not using a unicode character set, // use strchr instead. if( GlobalCharSet::Get() == 0 ) return ( strchr( str, c ) - str ); CharStep *s = CharStep::Create( str, GlobalCharSet::Get() ); for( char *ep = str + strlen( str ); s->Ptr() < ep; s->Next() ) { if( *s->Ptr() == c ) { p = s->Ptr(); break; } } if( p ) ret = p - str; delete s; return ret; } char *p4wI18n::convertText( CharSetCvt *cvt, char *s ) { // // Apply the character set converter and return // its result or NULL char *cvtPath = NULL; cvtPath = cvt->CvtBuffer( s, strlen( s ) ); if( cvt->LastErr() != CharSetCvt::NONE ) { delete [] cvtPath; cvtPath = NULL; } return cvtPath; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/util/p4wI18n.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |