本文整理汇总了C++中PString::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ PString::GetLength方法的具体用法?C++ PString::GetLength怎么用?C++ PString::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PString
的用法示例。
在下文中一共展示了PString::GetLength方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _rmdir
int _rmdir(const char *sDir)
{
USES_CONVERSION;
PString folderName = sDir;
if (folderName[folderName.GetLength() - 1] == PDIR_SEPARATOR) {
folderName.Delete(folderName.GetLength() - 1, 1);
}
return (RemoveDirectory(A2T(folderName)) ? 0 : -1);
}
示例2: GetBug
PString SIDStil::GetBug(PString relPathToEntry, int32 tuneNo)
{
if (baseDir.IsEmpty())
return ("");
// Older versions of STIL is detected
if (stilVersion < 2.59f)
tuneNo = 0;
// Find out whether we have this bug entry in the buffer.
// If the baseDir was changed, we'll have to read it in again,
// even if it might be in the buffer already
if ((bugBuf.Left(relPathToEntry.GetLength()) != relPathToEntry) || ((bugBuf.Find('\n') != relPathToEntry.GetLength()) && (stilVersion > 2.59f)))
{
// The relative pathnames don't match or they're not the same length:
// We don't have it in the buffer, so pull it in
try
{
PDirectory tempDir;
tempDir.SetDirectory(baseDir);
tempDir.Append("DOCUMENTS");
bugFile->Open(tempDir.GetDirectory() + "BUGlist.txt", PFile::pModeRead | PFile::pModeShareRead);
if (PositionToEntry(relPathToEntry, bugFile, bugDirs) == false)
{
// Copy the entry's name to the buffer
bugBuf = relPathToEntry + "\n";
}
else
{
bugBuf.MakeEmpty();
ReadEntry(bugFile, bugBuf);
}
bugFile->Close();
}
catch(PFileException e)
{
// Failed reading from the STIL.txt file
bugFile->Close();
return ("");
}
}
// Put the requested field into the result string
if (GetField(resultBug, bugBuf, tuneNo) != true)
return ("");
return (resultBug);
}
示例3: h323_make_call
/** Make a call to the remote endpoint.
*/
int h323_make_call(char *dest, call_details_t *cd, call_options_t *call_options)
{
int res;
PString token;
PString host(dest);
if (!h323_end_point_exist()) {
return 1;
}
res = endPoint->MakeCall(host, token, &cd->call_reference, call_options);
memcpy((char *)(cd->call_token), (const unsigned char *)token, token.GetLength());
return res;
};
示例4: Main
void MyProcess::Main() {
PString aor;
PString REGISTRAR_ADDRESS = "ekiga.net";
PString STUN_SERVER_ADDRESS = "stun.ekiga.net";
PString USER_NAME;
PString PASSWORD;
PString SIP_ADDRESS = "sip:[email protected]";
//PString SIP_ADDRESS = "sip:*[email protected]";
if (USER_NAME.GetLength() == 0 || PASSWORD.GetLength() == 0) {
std::cout << "Please set your username and password in the code." << std::endl;
return;
}
PTrace::Initialise(5, "log");
MyManager manager = MyManager();
// [Tom] TODO: Research why the NAT type is important.
PSTUNClient::NatTypes nat = manager.SetSTUNServer(STUN_SERVER_ADDRESS);
std::cout << "NAT type: " << nat << std::endl;
MyPCSSEndPoint * soundEp = new MyPCSSEndPoint(manager);
std::cout << "Sound output:" << std::endl;
std::cout << "===================================================================" << std::endl;
std::cout << soundEp->GetSoundChannelPlayDevice() << std::endl << std::endl;
std::cout << "Media formats:" << std::endl;
std::cout << "===================================================================" << std::endl;
std::cout << soundEp->GetMediaFormats() << std::endl << std::endl;
std::cout << "Registered formats:" << std::endl;
std::cout << "===================================================================" << std::endl;
std::cout << OpalMediaFormat::GetAllRegisteredMediaFormats() << std::endl << std::endl;
MySIPEndPoint * endPoint = new MySIPEndPoint(manager);
endPoint->SetDefaultLocalPartyName(USER_NAME);
endPoint->StartListeners(endPoint->GetDefaultListeners());
SIPRegister::Params params;
params.m_registrarAddress = REGISTRAR_ADDRESS;
params.m_addressOfRecord = USER_NAME;
params.m_password = PASSWORD;
std::cout << "Registering with " << params.m_registrarAddress << "; this may take a while..." << std::endl;
endPoint->Register(params, aor);
OpalMixerEndPoint * mixerEP = new OpalMixerEndPoint(manager, "mcu");
OpalMixerNodeInfo * mcuNodeInfo = new OpalMixerNodeInfo;
mcuNodeInfo->m_name = "Telekarma";
mixerEP->SetAdHocNodeInfo(mcuNodeInfo);
mixerEP->StartListeners(mixerEP->GetDefaultListeners());
int i;
for(i = 20; i > 0; i--) {
if (endPoint->IsRegistered(aor)) {
break;
}
PThread::Sleep(1000);
}
if (i > 0) {
std::cout << "Registration succeeded; aor=" << aor << std::endl;
std::cout << "Calling..." << std::endl;
PSafePtr<OpalCall> call2 = manager.SetUpCall("mcu:*", "pc:*");
PSafePtr<OpalCall> call = manager.SetUpCall("mcu:*", SIP_ADDRESS);
while(!call);
// manager.StartRecording("test.wav");
std::cout << "Connection will automatically terminate after 15 seconds..." << std::endl;
PThread::Sleep(15*1000);
// manager.StopRecording();
std::cout << "Connection automatically terminated by design." << std::endl;
call->Clear();
endPoint->Unregister(aor);
while(endPoint->IsRegistered(aor));
// [MV] maybe more to the exit/cleanup than this...
} else {
std::cout << "Registration attempt timed out." << std::endl;
}
std::cout << "Proof of concept main execution complete." << std::endl;
}
示例5: Open
bool Resources::Open(PString & argv0, PString & application) {
if(!PHYSFS_init(argv0.GetPointer())) {
PError << "failure while initialising physfs: " << PHYSFS_getLastError() << endl;
return PFalse;
} else {
PTRACE(5, "successful initialize physfs");
}
const char* basedir = PHYSFS_getBaseDir();
const char* userdir = PHYSFS_getUserDir();
const char* dirsep = PHYSFS_getDirSeparator();
char* writedir = new char[strlen(userdir) + application.GetLength() + 2];
sprintf(writedir, "%s.%s", userdir, application.GetPointer());
PTRACE(5, "physfs base directory: " << basedir);
PTRACE(5, "physfs user directory: " << userdir);
PTRACE(5, "physfs write directory: " << writedir);
if(!PHYSFS_setWriteDir(writedir)) {
// try to create the directory...
char* mkdir = new char[application.GetLength()+2];
sprintf(mkdir, ".%s", application.GetPointer());
if(!PHYSFS_setWriteDir(userdir) || ! PHYSFS_mkdir(mkdir)) {
delete[] writedir;
delete[] mkdir;
PError << "failed creating configuration directory: '" << writedir << "': " << PHYSFS_getLastError() << endl;
return PFalse;
}
delete[] mkdir;
if (!PHYSFS_setWriteDir(writedir)) {
PError << "couldn't set configuration directory to '" << writedir << "': " << PHYSFS_getLastError() << endl;
return PFalse;
}
}
PHYSFS_addToSearchPath(writedir, 0);
PHYSFS_addToSearchPath(basedir, 1);
delete[] writedir;
/* Root out archives, and add them to search path... */
if (resourceExt != NULL) {
char **rc = PHYSFS_enumerateFiles("/");
char **i;
size_t extlen = strlen(resourceExt);
char *ext;
for (i = rc; *i != NULL; i++) {
size_t l = strlen(*i);
if ((l > extlen) && ((*i)[l - extlen - 1] == '.')) {
ext = (*i) + (l - extlen);
if (strcasecmp(ext, resourceExt) == 0) {
PTRACE(5, "Add resource '" << *i << "' to search path");
const char *d = PHYSFS_getRealDir(*i);
char* str = new char[strlen(d) + strlen(dirsep) + l + 1];
sprintf(str, "%s%s%s", d, dirsep, *i);
addToSearchPath(str, 1);
delete[] str;
};
};
};
PHYSFS_freeList(rc);
}
return PTrue;
}
示例6: GetField
//.........这里部分代码省略.........
else
{
// Anything else is invalid as of v2.00
return (false);
}
}
else
{
// No. Handle it as a regular entry
if ((field == all) && ((tuneNo == 0) || (tuneNo == 1)))
{
// The complete entry was asked for. Simply copy the stuff in
result = buffer.Mid(start);
return (true);
}
else if (tuneNo == 1)
{
// A specific field was asked for
return (GetOneField(result, buffer.Mid(start), field));
}
else
{
// Anything else is invalid as of v2.00
return (false);
}
}
}
else
{
//-----------------//
// MULTITUNE ENTRY //
//-----------------//
int32 myTuneNo, nextTuneNo;
PString tuneNoStr;
// Was the complete entry asked for?
if (tuneNo == 0)
{
switch (field)
{
case all:
{
// Yes. Simply copy the stuff in
result = buffer.Mid(start);
return (true);
}
case comment:
{
// Only the file-global comment field was asked for
if (firstTuneNo != start)
return (GetOneField(result, buffer.Mid(start, firstTuneNo - start), comment));
else
return (false);
}
default:
{
// If a specific field other than a comment is
// asked for tuneNo=0, this is illegal
return (false);
}
}
}
// Search for the requested tune number
tuneNoStr.Format("(#%d)", tuneNo);
myTuneNo = buffer.Find(tuneNoStr, start);
if (myTuneNo != -1)
{
// We found the requested tune number.
// Set the pointer beyond it
myTuneNo = buffer.Find('\n', myTuneNo) + 1;
// Where is the next one?
nextTuneNo = buffer.Find("\n(#", myTuneNo);
if (nextTuneNo == -1)
{
// There is no next one - set pointer to the end of entry
nextTuneNo = buffer.GetLength();
}
else
{
// The search included the \n - go beyond it
nextTuneNo++;
}
// Put the desired fields into the result (which may be 'all')
PString tempResult;
bool retVal;
retVal = GetOneField(tempResult, buffer.Mid(myTuneNo, nextTuneNo - myTuneNo), field);
result += tempResult;
return (retVal);
}
else
return (false);
}
}
示例7: PositionToEntry
bool SIDStil::PositionToEntry(PString entryStr, PFile *inFile, PList<DirList *> &dirs)
{
DirList *item = NULL;
int32 slashIndex;
int32 startPos;
int32 i, count;
int32 pathLen, entryStrLen;
PString line;
bool foundIt = false;
bool globComm = false;
bool temp;
PCharSet_MS_WIN_1252 charSet;
try
{
// Seek to the start of the file
inFile->SeekToBegin();
// Get the dirpath
slashIndex = entryStr.ReverseFind('/');
// If no slash was found, something is screwed up in the entryStr
if (slashIndex == -1)
return (false);
pathLen = slashIndex + 1;
// Determine whether a section-global comment is asked for
entryStrLen = entryStr.GetLength();
if (pathLen == entryStrLen)
globComm = true;
// Find it in the table
count = dirs.CountItems();
for (i = 0; i < count; i++)
{
item = dirs.GetItem(i);
if (entryStr.Left(pathLen) == item->dirName)
{
foundIt = true;
break;
}
}
if (!foundIt)
{
// The directory was not found
return (false);
}
// Jump to the first entry of this section
inFile->Seek(item->position, PFile::pSeekBegin);
foundIt = false;
// Now find the desired entry
do
{
startPos = inFile->GetPosition();
line = inFile->ReadLine(&charSet);
if (inFile->IsEOF())
break;
// Check if it is the start of an entry
if (!line.IsEmpty() && (line.GetAt(0) == '/'))
{
if (line.Left(pathLen) != item->dirName)
{
// We are outside the section - get out of the loop,
// which will fail the search
break;
}
// Check whether we need to find a section-global comment or
// a specific entry
if (globComm || (stilVersion > 2.59f))
temp = (line == entryStr);
else
{
// To be compatible with older versions of STIL, which may have
// the tune designation on the first line of a STIL entry
// together with the pathname
temp = (line.Left(entryStrLen) == entryStr);
}
if (temp)
{
// Found it!
foundIt = true;
}
}
}
while (!foundIt);
if (foundIt)
{
// Reposition the file pointer back to the start of the entry
inFile->Seek(startPos, PFile::pSeekBegin);
return (true);
}
//.........这里部分代码省略.........
示例8: GetGlobalComment
PString SIDStil::GetGlobalComment(PString relPathToEntry)
{
PString dir;
int32 lastSlash, pathLen;
int32 temp;
if (baseDir.IsEmpty())
return ("");
// Save the dirpath
lastSlash = relPathToEntry.ReverseFind('/');
if (lastSlash == -1)
return ("");
pathLen = lastSlash + 1;
dir = relPathToEntry.Left(pathLen);
// Find out whether we have this global comment in the buffer.
// If the baseDir was changed, we'll have to read it in again,
// even if it might be in the buffer already
if ((globalBuf.Left(dir.GetLength()) != dir) || ((globalBuf.Find('\n') != pathLen) && (stilVersion > 2.59f)))
{
// The relative pathnames don't match or they're not the same length:
// We don't have it in the buffer, so pull it in
try
{
PDirectory tempDir;
tempDir.SetDirectory(baseDir);
tempDir.Append("DOCUMENTS");
stilFile->Open(tempDir.GetDirectory() + "STIL.txt", PFile::pModeRead | PFile::pModeShareRead);
if (PositionToEntry(dir, stilFile, stilDirs) == false)
{
// Copy the dirname to the buffer
globalBuf = dir + "\n";
}
else
{
globalBuf.MakeEmpty();
ReadEntry(stilFile, globalBuf);
}
stilFile->Close();
}
catch(PFileException e)
{
// Failed reading from the STIL.txt file
stilFile->Close();
return ("");
}
}
// Position the index to the global comment field
temp = globalBuf.Find('\n');
temp++;
// Check whether this is a NULL entry or not
if (temp == globalBuf.GetLength())
return ("");
return (globalBuf.Mid(temp));
}
示例9: GetOneField
bool SIDStil::GetOneField(PString &result, PString buffer, STILField field)
{
int32 temp = -1;
// Sanity check
if (buffer.GetAt(buffer.GetLength() - 1) != '\n')
{
result.MakeEmpty();
return (false);
}
switch (field)
{
case all:
result += buffer;
return (true);
case name:
temp = buffer.Find(_NAME_STR);
break;
case author:
temp = buffer.Find(_AUTHOR_STR);
break;
case title:
temp = buffer.Find(_TITLE_STR);
break;
case artist:
temp = buffer.Find(_ARTIST_STR);
break;
case comment:
temp = buffer.Find(_COMMENT_STR);
break;
default:
break;
}
// If the field was not found or it is not in between 'start'
// and 'end', it is declared a failure
if (temp == -1)
{
result.MakeEmpty();
return (false);
}
// Search for the end of this field. This is done by finding
// where the next field starts
int32 nextName, nextAuthor, nextTitle, nextArtist, nextComment, nextField;
nextName = buffer.Find(_NAME_STR, temp + 1);
nextAuthor = buffer.Find(_AUTHOR_STR, temp + 1);
nextTitle = buffer.Find(_TITLE_STR, temp + 1);
nextArtist = buffer.Find(_ARTIST_STR, temp + 1);
nextComment = buffer.Find(_COMMENT_STR, temp + 1);
// Now determine which one is the closest to our field - that one
// will mark the end of the required field
nextField = nextName;
if (nextField == -1)
nextField = nextAuthor;
else if ((nextAuthor != -1) && (nextAuthor < nextField))
nextField = nextAuthor;
if (nextField == -1)
nextField = nextTitle;
else if ((nextTitle != -1) && (nextTitle < nextField))
nextField = nextTitle;
if (nextField == -1)
nextField = nextArtist;
else if ((nextArtist != -1) && (nextArtist < nextField))
nextField = nextArtist;
if (nextField == -1)
nextField = nextComment;
else if ((nextComment != -1) && (nextComment < nextField))
nextField = nextComment;
if (nextField == -1)
nextField = buffer.GetLength();
// Now nextField points to the last+1 char that should be copied to
// result. Do that
result += buffer.Mid(temp, nextField - temp);
return (true);
}