String Directory::MakePathName(bool addSepFlag, const char *pathNameTrail) const { String pathName(_name); for (Directory *pDirectory = GetParent(); pDirectory != nullptr; pDirectory = pDirectory->GetParent()) { // a "boundary container" directory may have an empty name if (*pDirectory->GetName() != '\0' || pDirectory->IsRootContainer()) { String str(pDirectory->GetName()); size_t len = str.size(); if (len == 0 || !IsFileSeparator(str[len - 1])) { str += pDirectory->GetSeparator(); } str += pathName; pathName = str; } } if (pathNameTrail != nullptr) { size_t len = pathName.size(); if (len == 0 || !IsFileSeparator(pathName[len - 1])) { pathName += GetSeparator(); } for (const char *p = pathNameTrail; *p != '\0'; p++) { char ch = IsFileSeparator(*p)? GetSeparator() : *p; pathName += ch; } } else if (addSepFlag && IsContainer() && !_name.empty()) { size_t len = pathName.size(); if (len > 0 && !IsFileSeparator(pathName[len - 1])) { pathName += GetSeparator(); } } return pathName; }
bool Scanner::Next() { char currentChar; do { if(lastString) { currentToken = new Token(currentLine, currentPos, END_OF_FILE, DEFAULT, ""); return false; } currentChar = GetChar(); } while(IsSpace(currentChar) || IsTabulationSymbol(currentChar) || IsEndOfLine(currentChar)); if(IsCommentBegin(currentChar)) { char secondChar; if( IsCommentBegin(secondChar = GetChar()) ) { NextLine(); return Next(); } if(secondChar == '*') { while( GetChar() != '*' || !IsCommentBegin(GetChar()) ) {} return Next(); } else BackToPreviousChar(); } if(IsLetter(currentChar)) currentToken = GetIdentificator(currentChar); else if(IsNumber(currentChar)) currentToken = GetNumber(currentChar); else if(IsCharSeparator(currentChar)) currentToken = GetSymbol(currentChar); else if(IsStringSeparator(currentChar)) currentToken = GetString(currentChar); else if(IsSeparator(currentChar)) currentToken = GetSeparator(currentChar); else if(IsSpecialSymbol(currentChar)) currentToken = GetOperation(currentChar); else throw ScannerException(currentLine, currentPos, "Indefinite character: \"" + string(1, currentChar) + "\""); return true; }
Directory *Directory_FileSys::DoNext(Environment &env) { WIN32_FIND_DATA findData; if (_hFind == INVALID_HANDLE_VALUE) { String pathName(MakePathName(false)); if (!pathName.empty()) pathName += GetSeparator(); pathName += "*.*"; _hFind = ::FindFirstFile(OAL::ToNativeString(pathName.c_str()).c_str(), &findData); if (_hFind == INVALID_HANDLE_VALUE) return nullptr; } else if (!::FindNextFile(_hFind, &findData)) { ::FindClose(_hFind); _hFind = INVALID_HANDLE_VALUE; return nullptr; } while (::strcmp(findData.cFileName, ".") == 0 || ::strcmp(findData.cFileName, "..") == 0) { if (!::FindNextFile(_hFind, &findData)) { ::FindClose(_hFind); _hFind = INVALID_HANDLE_VALUE; return nullptr; } } Type type = (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? TYPE_Container : TYPE_Item; String fileName = OAL::FromNativeString(findData.cFileName); return new Directory_FileSys(Directory::Reference(this), fileName.c_str(), type, new OAL::FileStat(fileName.c_str(), findData)); }
// Find COpcBrowseElement* COpcBrowseElement::Find(const COpcString& cPath) { // remove leading separator - if it exists. COpcString cPrefix = GetSeparator(); COpcString cLocalPath = cPath; while (cLocalPath.Find(GetSeparator()) == 0) { cLocalPath = cLocalPath.SubStr(cPrefix.GetLength()); } // recursively search children. OPC_POS pos = m_cChildren.GetHeadPosition(); while (pos != NULL) { COpcBrowseElement* pChild = m_cChildren.GetNext(pos); // check for a child with an exact name match. if (cLocalPath == pChild->m_cName) { return pChild; } // check if the path starts with the child name. COpcString cPrefix = pChild->m_cName + pChild->GetSeparator(); // check for a child with an exact name match plus trailing separator. if (cLocalPath == cPrefix) { return pChild; } UINT uIndex = cLocalPath.Find(cPrefix); // search the child node if there is a match. if (uIndex == 0) { cLocalPath = cLocalPath.SubStr(cPrefix.GetLength()); return pChild->Find(cLocalPath); } } return NULL; }
bool udtPath::Combine(udtString& combinedPath, udtVMLinearAllocator& allocator, const udtString& folderPath, const udtString& extra) { const bool isSeparatorNeeded = !HasTrailingSeparator(folderPath); const udtString path = udtString::IsNullOrEmpty(folderPath) ? udtString::NewConstRef(".") : folderPath; const udtString separator = isSeparatorNeeded ? udtString::NewConstRef(GetSeparator()) : udtString::NewEmptyConstant(); const udtString* strings[] = { &path, &separator, &extra }; combinedPath = udtString::NewFromConcatenatingMultiple(allocator, strings, (u32)UDT_COUNT_OF(strings)); return true; }
std::string Vpath::ToString () const { Vpath::const_iterator it = begin (); if (it == end ()) return std::string (); std::string strPath (*it); ++it; while (it != end ()) { strPath += GetSeparator(); strPath += *it; ++it; } return strPath; }
// Browse void COpcBrowseElement::Browse( const COpcString& cPath, bool bFlat, COpcStringList& cNodes ) { if (!bFlat) { OPC_POS pos = m_cChildren.GetHeadPosition(); while (pos != NULL) { COpcBrowseElement* pNode = m_cChildren.GetNext(pos); // add child to list. cNodes.AddTail(pNode->GetName()); } } else { OPC_POS pos = m_cChildren.GetHeadPosition(); while (pos != NULL) { COpcBrowseElement* pNode = m_cChildren.GetNext(pos); // add child to list. cNodes.AddTail(cPath + pNode->GetName()); // recursively browse children. if (pNode->m_cChildren.GetCount() > 0) { pNode->Browse(cPath + pNode->GetName() + GetSeparator(), bFlat, cNodes); } } } }
//--------------------------------------------------------------------------- bool TData::ImportPointSeries(const std::wstring &FileName, char Separator) { const TColor Colors[] = {clRed, clGreen, clBlue, clYellow, clPurple, clAqua, clBlack, clGray, clSkyBlue , clMoneyGreen, clDkGray}; std::ifstream Stream(FileName.c_str()); if(!Stream) { MessageBox(LoadRes(RES_NOT_GRAPH_FILE, FileName), LoadString(RES_FILE_ERROR), MB_ICONSTOP); return false; } std::string Line; while(Stream && Line.empty()) std::getline(Stream, Line); if(Separator == 0) Separator = GetSeparator(Line); std::vector<std::pair<std::wstring, std::vector<TPointSeriesPoint> > > Points; unsigned Row = 0; try { boost::escaped_list_separator<char> Sep("", std::string(1, Separator), ""); unsigned Index = 0; do { ++Row; boost::tokenizer<boost::escaped_list_separator<char> > tok(Line, Sep); boost::tokenizer<boost::escaped_list_separator<char> >::iterator beg = tok.begin(); std::wstring xStr = ToWString(*beg); if(!xStr.empty() && xStr[0] == L'#') { Index = Points.size(); Points.push_back(std::make_pair(xStr.substr(1), std::vector<TPointSeriesPoint>())); while(++beg != tok.end()) Points.push_back(std::make_pair(ToWString(*beg), std::vector<TPointSeriesPoint>())); } else { unsigned Col = Index; while(++beg != tok.end()) { if(Col == Points.size()) Points.push_back(std::make_pair(L"", std::vector<TPointSeriesPoint>())); std::wstring yStr = ToWString(*beg); if(Property.DecimalSeparator != '.') { std::replace(xStr.begin(), xStr.end(), Property.DecimalSeparator, L'.'); std::replace(yStr.begin(), yStr.end(), Property.DecimalSeparator, L'.'); } Points[Col].second.push_back(TPointSeriesPoint(xStr, yStr)); Col++; } } } while(std::getline(Stream, Line)); } catch(Func32::EParseError &E) { MessageBox(LoadRes(526, FileName.c_str(), Row+1), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } catch(std::out_of_range &E) { MessageBox(LoadRes(526, FileName.c_str(), Row+1), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } catch(std::bad_alloc &E) { MessageBox(LoadRes(RES_OUT_OF_MEMORY), LoadRes(RES_FILE_ERROR), MB_ICONSTOP); return false; } unsigned ColorIndex = 0; unsigned Style = Property.DefaultPoint.Style; unsigned LineStyle = Property.DefaultPointLine.Style; UndoList.BeginMultiUndo(); for(unsigned I = 0; I < Points.size(); I++) { boost::shared_ptr<TPointSeries> Series(new TPointSeries( clBlack, //FrameColor Colors[ColorIndex], //FillColor Colors[ColorIndex], //LineColor Property.DefaultPoint.Size, //Size Property.DefaultPointLine.Size, //LineSize Style, //Style static_cast<TPenStyle>(LineStyle), //LineStyle iaLinear, //Onterpolation false, //ShowLabels Property.DefaultPointLabelFont, //Font lpBelow, //LabelPosition ptCartesian, //PointType ebtNone, //xErrorBarType 0, //xErrorValues ebtNone, //yErrorBarType 0 //yErrorValue )); Series->Swap(Points[I].second); Series->SetLegendText(Points[I].first.empty() ? CreatePointSeriesDescription() : Points[I].first); Insert(Series); UndoList.Push(TUndoAdd(Series)); Series->Update(); ColorIndex = ++ColorIndex % (sizeof(Colors)/sizeof(TColor)); Style = (Style+1) % 7; LineStyle = (LineStyle+1) % 5; } UndoList.EndMultiUndo(); Modified = true; return true; }
// Insert COpcBrowseElement* COpcBrowseElement::Insert(const COpcString& cPath) { COpcString cName = cPath; COpcString cSubPath = OPC_EMPTY_STRING; // check if multiple levels have been specified. do { UINT uIndex = cName.Find(GetSeparator()); if (uIndex == -1) { break; } cSubPath = cName.SubStr(uIndex + GetSeparator().GetLength()); cName = cName.SubStr(0, uIndex); if (!cName.IsEmpty()) { break; } cName = cSubPath; } while (!cSubPath.IsEmpty()); // invalid path specified. if (cName.IsEmpty()) { return NULL; } // find out if node already exists. COpcBrowseElement* pNode = NULL; OPC_POS pos = m_cChildren.GetHeadPosition(); while (pos != NULL) { pNode = m_cChildren.GetNext(pos); if (pNode->m_cName == cName) { // return existing node. if (cSubPath.IsEmpty()) { return pNode; } // insert sub-path into existing node. return pNode->Insert(cSubPath); } } // create new node. pNode = CreateInstance(); pNode->m_cName = cName; OPC_ASSERT(!pNode->m_cName.IsEmpty()); COpcBrowseElement* pChild = pNode; if (!cSubPath.IsEmpty()) { pChild = pNode->Insert(cSubPath); if (pChild == NULL) { delete pNode; return NULL; } } m_cChildren.AddTail(pNode); return pChild; }
foreach (QmitkNodeDescriptor* descr, nodeDescriptors) { actions.append(lastDescriptor->GetSeparator()); lastDescriptor = descr; actions.append(lastDescriptor->GetBatchActions()); }
std::string Basename(const std::string &Path) { size_t Pos = Path.rfind(GetSeparator()); if (Pos == std::string::npos) return Path; assert(Pos < Path.size()); return Path.substr(Pos + 1); }
std::string DirPlusFile(const std::string &DirPath, const std::string &FileName) { return DirPath + GetSeparator() + FileName; }