// Get file name from path STRING Port::FileName(STRING file) { #ifdef WIN32 #ifdef UNICODE int pos = file.find_last_of(L"\\") + 1; #else int pos = file.find_last_of("\\") + 1; #endif #elif defined(UNIX) #ifdef UNICODE int pos = file.find_last_of(L"/") + 1; #else int pos = file.find_last_of("/") + 1; #endif #endif return file.substr(pos); }
void MgWmsLayerDefinitions::GenerateDefinitions(MgUtilDictionary& Dictionary) { MgXmlSynchronizeOnElement ResourceDocument(*m_xmlParser,_("ResourceDocument")); if(!ResourceDocument.AtBegin()) return; // Something is wrong. We leave. while(!ResourceDocument.AtEnd()) { STRING sValue; // basic_string if(GetElementContents(_("ResourceId"),sValue)) { // Okay, the ResourceId is too decorated for our purposes; // the outside world doesn't need to know (and clutter up // URL command lines with) this syntactic "punctuation" so // we just get rid of it. // Remove the Library prefix, if present. if(sValue.find(_("Library://")) == 0) sValue = sValue.substr(10); // Remove the LayerDefinition suffix, if present. STRING::size_type iEnd = sValue.find(_(".LayerDefinition")); if(iEnd != STRING::npos) sValue.resize(iEnd); // There, that's our Layer Name. Dictionary.AddDefinition(_("Layer.Name"),sValue); // Until we have "Friendly Name" support, the // friendly name will simply be the layer name sans // path. iEnd = sValue.find_last_of('/'); if(iEnd != STRING::npos) sValue = sValue.substr(iEnd+1); // one past the slash. // That's our Layer Title, // Note that subsequently-found metadata may override this // definition with a real title... one that the user actually // wants. This just provides a default in case no such // friendly name exists.... that keeps the list of layer names // from being a list of empty strings. Dictionary.AddDefinition(_("Layer.Title"),sValue); } else if(!GetMetadataDefinitions(Dictionary)) { SkipElement(NULL); } } }
// Remove the path from a file name. STRING removePath(const STRING str) { return str.substr(str.find_last_of(_T('\\')) + 1); }