void nuiHTML::GetAbsoluteURL(const nglString& rBaseURL, nglString& url) { int32 colon = url.Find(':'); if (colon > 0) { // complete url link } else if (url[0] == '/') { // Site absolute int32 col = rBaseURL.Find(_T("://")); if (col > 0) { int32 end = rBaseURL.Find('/', col + 3); if (end) url = rBaseURL.Extract(0, end) + url; } } else { // Site relative int32 end = rBaseURL.FindLast(_T('/')); if (end >= 0) { url = rBaseURL.Extract(0, end + 1) + url; } else { url = rBaseURL + _T("/") + url; } } Canonize(url); }
void nuiLayout::SetConstraint(nuiWidget* pWidget, const nglString& rDescription) { nuiLayoutConstraint constraintH, constraintV; int pos = rDescription.Find('/'); if (pos < 0) { nglString desc(rDescription); desc.Trim(); constraintH.Set(desc); } else if (pos == 0) { nglString desc2 = rDescription.Extract(pos+1, rDescription.GetLength() - (pos + 1)); desc2.Trim(); constraintV.Set(desc2); } else { nglString desc1 = rDescription.Extract(0, pos); nglString desc2 = rDescription.Extract(pos+1, rDescription.GetLength() - (pos + 1)); desc1.Trim(); desc2.Trim(); constraintH.Set(desc1); constraintV.Set(desc2); } SetConstraint(pWidget, constraintH, constraintV); }
// Stolen from nglPath! static int32 GetRootPart(const nglString& rStr) { if (rStr[0] == _T('/')) { if (rStr[1] != _T('/')) return 1; // //host[/path] (network address) // or /volume[/path] (standard unix like path) int32 end = rStr.Find(_T('/'), 2); return ((end > 0) ? end : rStr.GetLength()); } // Find the protocol name: int col = rStr.Find(_T("://"), 0, true); return MIN(col + 3, rStr.GetLength()); }
static bool Canonize(nglString& rStr) { nglString canon; int32 len = rStr.GetLength(); int32 root_part = GetRootPart(rStr); int32 last_slash = root_part; int32 slash = 0; canon = rStr.GetLeft(root_part); while (slash < len) { slash = rStr.Find(_T('/'), last_slash); if (slash == - 1) slash = len; if (((slash - last_slash) == 1) && (rStr.GetChar(last_slash) == _T('.'))) { // Ignore '.' } else if (((slash - last_slash) == 2) && (!rStr.Compare(_T(".."), last_slash, 2))) { // Interpret '..' int32 prev_slash = canon.FindLast(_T('/')); if (prev_slash < root_part) prev_slash = root_part; if (!canon.IsEmpty() && canon.Compare(_T(".."), canon.GetLength() - 2, 2)) canon.Delete(prev_slash); else { if (canon.GetLength() > root_part) canon += _T('/'); canon += _T(".."); } } else { // Simply append path node nglString node = rStr.Extract(last_slash, (slash - last_slash)); if (canon.GetLength() > root_part) canon += _T('/'); canon += node; } last_slash = slash + 1; } rStr = canon; return true; }
nuiWidgetPtr nuiContainer::Find(const nglString& rName) { CheckValid(); int slash = rName.Find('/'); if (slash >= 0) { nglString path = rName.GetLeft(slash); nglString rest = rName.Extract(slash + 1); nuiWidgetPtr node = SearchForChild(path, false); return node ? node->Find(rest) : NULL; } else return SearchForChild(rName,false); }