/* static */ wxString wxFileSystemHandler::GetProtocol(const wxString& location) { wxString s = wxEmptyString; int i, l = location.length(); bool fnd = false; for (i = l-1; (i >= 0) && ((location[i] != wxT('#')) || (!fnd)); i--) { if ((location[i] == wxT(':')) && (i != 1 /*win: C:\path*/)) fnd = true; } if (!fnd) return wxT("file"); for (++i; (i < l) && (location[i] != wxT(':')); i++) s << location[i]; return s; }
inline int DetectRepeatingSymbols(wxString const &str, int pos) { int newPos = -1, currPos = pos; while (1) { if (currPos + 4 >= static_cast<int>(str.length())) break; if (str[currPos + 1] != wxT(',')) break; if (str[currPos + 3] == wxT('\'')) { const wxString &s = str.substr(currPos + 3, str.length() - (currPos + 3)); if (regexRepeatedChars.Matches(s)) { size_t start, length; regexRepeatedChars.GetMatch(&start, &length, 0); newPos = currPos + 3 + length; if ((newPos + 4 < static_cast<int>(str.length())) && str[newPos] == wxT(',') && str[newPos + 2] == wxT('"')) { newPos += 3; while (newPos < static_cast<int>(str.length()) && str[newPos] != wxT('"')) ++newPos; if (newPos + 1 < static_cast<int>(str.length()) && str[newPos] == wxT('"')) ++newPos; } currPos = newPos; } else break; } else break; // move the current position to point at the '"' character currPos--; } return newPos; }
// if necessary truncates the given string and adds an ellipsis wxString EllipsizeString(const wxString &text) { if (ms_maxLength > 0 && text.length() > ms_maxLength) { wxString ret(text); ret.Truncate(ms_maxLength); ret << "..."; return ret; } return text; }
wxArrayInt wxPdfFontData::GetKerningWidthArray(const wxString& s) const { bool translateChar2Glyph = m_type.IsSameAs(wxT("TrueTypeUnicode")) || m_type.IsSameAs(wxT("OpenTypeUnicode")); wxArrayInt widths; int pos = 0; if (m_kp != NULL && s.length()) { wxPdfKernPairMap::const_iterator kpIter; wxPdfKernWidthMap::const_iterator kwIter; wxUint32 ch1, ch2; wxString::const_iterator ch = s.begin(); ch1 = (wxUint32) (*ch); if (translateChar2Glyph && m_gn != NULL) { wxPdfChar2GlyphMap::const_iterator glyphIter; glyphIter = m_gn->find(ch1); if (glyphIter != m_gn->end()) { ch1 = glyphIter->second; } } for (++ch; ch != s.end(); ++ch) { ch2 = (wxUint32) (*ch); if (translateChar2Glyph && m_gn != NULL) { wxPdfChar2GlyphMap::const_iterator glyphIter; glyphIter = m_gn->find(ch2); if (glyphIter != m_gn->end()) { ch2 = glyphIter->second; } } kpIter = (*m_kp).find(ch1); if (kpIter != (*m_kp).end()) { kwIter = kpIter->second->find(ch2); if (kwIter != kpIter->second->end()) { widths.Add(pos); widths.Add(-kwIter->second); } } ch1 = ch2; ++pos; } } return widths; }
// Notice we don't check here the font. It is supposed to be OK before the call. void wxTextMeasure::DoGetTextExtent(const wxString& string, wxCoord *width, wxCoord *height, wxCoord *descent, wxCoord *externalLeading) { SIZE sizeRect; const size_t len = string.length(); if ( !::GetTextExtentPoint32(m_hdc, string.t_str(), len, &sizeRect) ) { wxLogLastError(wxT("GetTextExtentPoint32()")); } // the result computed by GetTextExtentPoint32() may be too small as it // accounts for under/overhang of the first/last character while we want // just the bounding rect for this string so adjust the width as needed if ( len > 0 ) { ABC widthABC; const wxChar chFirst = *string.begin(); if ( ::GetCharABCWidths(m_hdc, chFirst, chFirst, &widthABC) ) { if ( widthABC.abcA < 0 ) sizeRect.cx -= widthABC.abcA; if ( len > 1 ) { const wxChar chLast = *string.rbegin(); ::GetCharABCWidths(m_hdc, chLast, chLast, &widthABC); } //else: we already have the width of the last character if ( widthABC.abcC < 0 ) sizeRect.cx -= widthABC.abcC; } //else: GetCharABCWidths() failed, not a TrueType font? } *width = sizeRect.cx; *height = sizeRect.cy; if ( descent || externalLeading ) { TEXTMETRIC tm; ::GetTextMetrics(m_hdc, &tm); if ( descent ) *descent = tm.tmDescent; if ( externalLeading ) *externalLeading = tm.tmExternalLeading; } }
bool parseColor(wxColour& result, wxString value) { if (value.length() == 7 && value[0] == wxT('#')) { unsigned r = 0, g = 0, b = 0; if (wxT('0') <= value[1] && value[1] <= wxT('9')) r = r * 10 + (value[1] - wxT('0')); else if (wxT('A') <= value[1] && value[1] <= wxT('F')) r = r * 10 + (value[1] - wxT('A')) + 10; else return false; if (wxT('0') <= value[2] && value[2] <= wxT('9')) r = r * 10 + (value[2] - wxT('0')); else if (wxT('A') <= value[2] && value[2] <= wxT('F')) r = r * 10 + (value[2] - wxT('A')) + 10; else return false; if (wxT('0') <= value[3] && value[3] <= wxT('9')) g = g * 10 + (value[3] - wxT('0')); else if (wxT('A') <= value[3] && value[3] <= wxT('F')) g = g * 10 + (value[3] - wxT('A')) + 10; else return false; if (wxT('0') <= value[4] && value[4] <= wxT('9')) g = g * 10 + (value[4] - wxT('0')); else if (wxT('A') <= value[4] && value[4] <= wxT('F')) g = g * 10 + (value[4] - wxT('A')) + 10; else return false; if (wxT('0') <= value[5] && value[5] <= wxT('9')) b = b * 10 + (value[5] - wxT('0')); else if (wxT('A') <= value[5] && value[5] <= wxT('F')) b = b * 10 + (value[5] - wxT('A')) + 10; else return false; if (wxT('0') <= value[6] && value[6] <= wxT('9')) b = b * 10 + (value[6] - wxT('0')); else if (wxT('A') <= value[6] && value[6] <= wxT('F')) b = b * 10 + (value[6] - wxT('A')) + 10; else return false; result.Set(r, g, b); return true; } return false; }
//-------------------------------------------------------------------------------- wxString CIwASDFileDataAttr::Group::MakeAbsolute(const wxString& fileName) { wxString name2; if (fileName.length()>=2 && fileName[0]=='.' && (fileName[1]=='\\' || fileName[1]=='/')) name2=m_Parent->m_File->m_Paths[0]->m_Parent->c_str(); else if (m_Parent->m_File->m_Paths[0]->GetRoot()!=NULL) name2=m_Parent->m_File->m_Paths[0]->GetRoot()->c_str(); if (name2.EndsWith(L"\\") || name2.EndsWith(L"/")) name2.RemoveLast(); if (fileName.length()>=2 && fileName[0]=='.' && (fileName[1]=='\\' || fileName[1]=='/')) name2+=fileName.Mid(1); else { if (fileName[0]!='\\' && fileName[1]!='/') name2+=L"/"; name2+=fileName; } return name2; }
wxFileName FileViewer::GetFilename(wxString ref) const { if ( ref.length() >= 3 && ref[1] == _T(':') && (ref[2] == _T('\\') || ref[2] == _T('/')) ) { // This is an absolute Windows path (c:\foo... or c:/foo...); fix // the latter case. ref.Replace("/", "\\"); } wxPathFormat pathfmt = ref.Contains(_T('\\')) ? wxPATH_WIN : wxPATH_UNIX; wxFileName filename(ref.BeforeLast(_T(':')), pathfmt); if ( filename.IsRelative() ) { wxFileName relative(filename); wxString basePath(m_basePath); // Sometimes, the path in source reference is not relative to the PO // file's location, but is relative to e.g. the root directory. See // https://code.djangoproject.com/ticket/13936 for exhaustive // discussion with plenty of examples. // // Deal with this by trying parent directories of m_basePath too. So if // a file named project/locales/cs/foo.po has a reference to src/main.c, // try not only project/locales/cs/src/main.c, but also // project/locales/src/main.c and project/src/main.c etc. while ( !basePath.empty() ) { filename = relative; filename.MakeAbsolute(basePath); if ( filename.FileExists() ) { break; // good, found the file } else { // remove the last path component size_t last = basePath.find_last_of("\\/"); if ( last == wxString::npos ) break; else basePath.erase(last); } } } return filename; }
usi interprete::ParenNumCarac(wxString parentesis) { usi i=0; char a=parentesis.GetChar(0); if(a=='('||a=='{') { for(i=0;i<parentesis.length();i++) { if(parentesis.GetChar(i)==',') break; } } return i; }
int ContextBase::FindNext(const wxString& what, int& pos) { wxStyledTextCtrl* ctrl = GetCtrl().GetCtrl(); int startpos = ctrl->PositionFromLine(ctrl->GetFirstVisibleLine()); int lastLine = ctrl->GetFirstVisibleLine() + ctrl->LinesOnScreen(); int endpos = ctrl->GetLineEndPosition(lastLine); if((pos < startpos) || (pos > endpos)) return wxNOT_FOUND; int where = ctrl->FindText(pos, endpos, what); if(where != wxNOT_FOUND) { pos = where + what.length(); } return where; }
bool wxFile::Write(const wxString& s, const wxMBConv& conv) { const wxWX2MBbuf buf = s.mb_str(conv); if ( !buf ) return false; #if wxUSE_UNICODE const size_t size = buf.length(); #else const size_t size = s.length(); #endif return Write(buf, size) == size; }
wxString mmReportBudget::AdjustYearValues(int& day, int& month, long year, wxString yearStr) { if ((yearStr.length() < 5)) { if (mmIniOptions::instance().budgetFinancialYears_) { GetFinancialYearValues(day, month); yearStr = wxString::Format(_("Financial Year: %s - %i"), yearStr, (year + 1)); } else yearStr = wxString::Format(_("Year: %s"), yearStr); } else { yearStr = wxString::Format(_("Month: %s"), yearStr); } return yearStr; }
/* static */ wxString wxFileSystemHandler::GetAnchor(const wxString& location) { wxChar c; int l = location.length(); for (int i = l-1; i >= 0; i--) { c = location[i]; if (c == wxT('#')) return location.Right(l-i-1); else if ((c == wxT('/')) || (c == wxT('\\')) || (c == wxT(':'))) return wxEmptyString; } return wxEmptyString; }
void XDebugComThread::DoSendCommand(const wxString& command, clSocketBase::Ptr_t client) { // got message, process it if(!client) { return; } CL_DEBUGS(wxString() << "CodeLite >>> " << command); wxMemoryBuffer buff; buff.AppendData(command.mb_str(wxConvISO8859_1), command.length()); buff.AppendByte(0); std::string cmd((const char*)buff.GetData(), buff.GetDataLen()); client->Send(cmd); }
void SearchTreeNode::Dump(BasicSearchTree* tree, nSearchTreeNode node_id, const wxString& prefix, wxString& result) { wxString suffix(_T("")); suffix << _T("- \"") << SerializeString(GetLabel(tree)) << _T("\" (") << U2S(node_id) << _T(")"); if (prefix.length() && prefix[prefix.length()-1]=='|') result << prefix.substr(0,prefix.length()-1) << _T('+') << suffix << _T('\n'); else if (prefix.length() && prefix[prefix.length()-1]==' ') result << prefix.substr(0,prefix.length()-1) << _T('\\') << suffix << _T('\n'); else result << prefix << suffix << _T('\n'); wxString newprefix(prefix); newprefix.append(suffix.length() - 2, _T(' ')); newprefix << _T("|"); SearchTreeLinkMap::iterator i; unsigned int cnt = 0; for (i = m_Children.begin(); i!= m_Children.end(); i++) { if (cnt == m_Children.size() - 1) newprefix[newprefix.length() - 1] = _T(' '); tree->GetNode(i->second,false)->Dump(tree,i->second,newprefix,result); cnt++; } }
// Return just the directory, or NULL if no directory wxString wxPathOnly (const wxString& path) { if (!path.empty()) { wxChar buf[_MAXPATHLEN]; int l = path.length(); int i = l - 1; if ( i >= _MAXPATHLEN ) return wxString(); // Local copy wxStrcpy(buf, path); // Search backward for a backward or forward slash while (i > -1) { // Unix like or Windows if (path[i] == wxT('/') || path[i] == wxT('\\')) { // Don't return an empty string if (i == 0) i ++; buf[i] = 0; return wxString(buf); } #ifdef __VMS__ if (path[i] == wxT(']')) { buf[i+1] = 0; return wxString(buf); } #endif i --; } #if defined(__WINDOWS__) // Try Drive specifier if (wxIsalpha (buf[0]) && buf[1] == wxT(':')) { // A:junk --> A:. (since A:.\junk Not A:\junk) buf[2] = wxT('.'); buf[3] = wxT('\0'); return wxString(buf); } #endif } return wxEmptyString; }
void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale, const wxString& str, int* width, int* height, int* ascent, int* descent) { XRectangle ink, logical; WXFontSet fset = font.GetFontSet(scale, display); XmbTextExtents( (XFontSet)fset, str.mb_str(), str.length(), &ink, &logical); if( width ) *width = logical.width; if( height ) *height = logical.height; if( ascent ) *ascent = -logical.y; if( descent ) *descent = logical.height + logical.y; }
bool wxTextMeasureBase::GetPartialTextExtents(const wxString& text, wxArrayInt& widths, double scaleX) { widths.Empty(); if ( text.empty() ) return true; MeasuringGuard guard(*this); widths.Add(0, text.length()); return DoGetPartialTextExtents(text, widths, scaleX); }
wxString PostgresPreparedStatement::TranslateSQL(const wxString& strOriginalSQL) { int nParameterIndex = 1; wxString strReturn = wxEmptyString;//strOriginalSQL; /* int nFound = strReturn.Replace(_("?"), wxString::Format(_("$%d"), nParameterIndex), false); while (nFound != 0) { nParameterIndex++; nFound = strReturn.Replace(_("?"), wxString::Format(_("$%d"), nParameterIndex), false); } */ bool bInStringLiteral = false; size_t len = strOriginalSQL.length(); for (size_t i = 0; i < len; i++) { wxChar character = strOriginalSQL[i]; if ('\'' == character) { // Signify that we are inside a string literal inside the SQL bInStringLiteral = !bInStringLiteral; // Pass the character on to the return string strReturn += character; } else { if ('?' == character) { if (bInStringLiteral) { // Pass the character on to the return string strReturn += character; } else { // Replace the question mark with a prepared statement placeholder strReturn += wxString::Format(_("$%d"), nParameterIndex); nParameterIndex++; } } else { // Pass the character on to the return string strReturn += character; } } } return strReturn; }
bool parseCDouble(double& result, wxString value) { bool sign = false; unsigned pos; double shift = 0.1; result = 0; if (value.length() > 0 && value[0] == wxT('-')) { sign = true; value = value.Mid(1); } if (value.length() < 1) return false; for (pos = 0; pos < value.length(); pos++) { if (value[pos] == wxT('.')) { if (pos == 0) return false; pos++; break; } if (value[pos] < wxT('0') || wxT('9') < value[pos]) return false; result = result * 10 + (value[pos] - wxT('0')); } for (; pos < value.length(); pos++) { if (value[pos] < wxT('0') || wxT('9') < value[pos]) return false; result = result + shift * (value[pos] - wxT('0')); shift = shift / 10; } if (sign) result = -result; return true; }
/** * Function XmlEsc * translates '<' to "<", '>' to ">" and so on, according to the spec: * http://www.w3.org/TR/2000/WD-xml-c14n-20000119.html#charescaping * May be moved to a library if needed generally, but not expecting that. */ static wxString XmlEsc( const wxString& aStr, bool isAttribute = false ) { wxString escaped; escaped.reserve( aStr.length() ); for( wxString::const_iterator it = aStr.begin(); it != aStr.end(); ++it ) { const wxChar c = *it; switch( c ) { case wxS( '<' ): escaped.append( wxS( "<" ) ); break; case wxS( '>' ): escaped.append( wxS( ">" ) ); break; case wxS( '&' ): escaped.append( wxS( "&" ) ); break; case wxS( '\r' ): escaped.append( wxS( "
" ) ); break; default: if( isAttribute ) { switch( c ) { case wxS( '"' ): escaped.append( wxS( """ ) ); break; case wxS( '\t' ): escaped.append( wxS( "	" ) ); break; case wxS( '\n' ): escaped.append( wxS( "
" )); break; default: escaped.append(c); } } else escaped.append(c); } } return escaped; }
void DisassemblyTextCtrl::OnGPM(wxMouseEvent& event) { if(platform::gtk == false) // only if GPM is not already implemented by the OS { int pos = PositionFromPoint(wxPoint(event.GetX(), event.GetY())); if(pos == wxSCI_INVALID_POSITION) return; int start = GetSelectionStart(); int end = GetSelectionEnd(); const wxString s = GetSelectedText(); if(pos < GetCurrentPos()) { start += s.length(); end += s.length(); } InsertText(pos, s); SetSelectionVoid(start, end); } } // end of OnGPM
static void arrange_indirection_tokens_between( wxString& type, wxString& identifier ) { // TBD:: FIXME:: return value of operators ! while ( identifier[0u] == _T('*') || identifier[0u] == _T('&') ) { type += identifier[0u]; identifier.erase(0,1); if ( !identifier.length() ) return; } }
static int get_text_height(wxDC &dc, const wxString &text) { int width, height; dc.GetTextExtent(text, &width, &height); // GetTextExtent only takes into account one line, so just count the \n's // and multiply the height by that. int text_len = text.length(); int times = 1; for (int i = 0; i < text_len; ++i) { if (text[i] == wxT('\n')) ++times; } return times * height; }
/* static */ wxString wxFileSystemHandler::GetRightLocation(const wxString& location) { int i, l = location.length(); int l2 = l + 1; for (i = l-1; (i >= 0) && ((location[i] != wxT(':')) || (i == 1) || (location[i-2] == wxT(':'))); i--) { if (location[i] == wxT('#')) l2 = i + 1; } if (i == 0) return wxEmptyString; else return location.Mid(i + 1, l2 - i - 2); }
void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y) { wxCHECK_RET( Ok(), wxT("wxGCDC(cg)::DoDrawRotatedText - invalid DC") ); if ( str.length() == 0 ) return; if ( !m_logicalFunctionSupported ) return; if ( m_backgroundMode == wxTRANSPARENT ) m_graphicContext->DrawText( str, x ,y); else m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); }
wxString interprete::ObtenerPolinomioParen(wxString parentesis) { wxString obpa; char a=parentesis.GetChar(0); if(a=='('||a=='{') { obpa=parentesis.Mid(1,(parentesis.length()-1)); } else { return "error"; //for(i=0;i<parentesis.length();i++){} } return obpa; }
wxString inline_string_encode(wxString &input) { const size_t inlen = input.length(); wxString output(_T("")); output.Alloc(inlen); for (size_t i = 0; i < inlen; i++) { wxChar c = input[i]; if (c <= 0x1F || c == 0x23 || c == 0x2C || c == 0x3A || c == 0x7C) { output << wxString::Format(_T("#%02X"), c); } else { output << c; } } return output; }
int CatalogItemsComparator::CompareStrings(wxString a, wxString b) const { a.Replace("&", ""); a.Replace("_", ""); b.Replace("&", ""); b.Replace("_", ""); if (m_collator) { UErrorCode err = U_ZERO_ERROR; #if wxUSE_UNICODE_UTF8 return m_collator->compareUTF8(a.wx_str(), b.wx_str(), err); #elif SIZEOF_WCHAR_T == 2 return m_collator->compare(a.wx_str(), a.length(), b.wx_str(), b.length(), err); #else return m_collator->compare(str::to_icu(a), str::to_icu(b), err); #endif } else { return a.CmpNoCase(b); } }
inline unsigned int SearchTreeNode::GetDeepestMatchingPosition(BasicSearchTree* tree, const wxString& s,unsigned int StringStartDepth) { if (StringStartDepth >= GetDepth()) return GetDepth(); if (StringStartDepth + s.length() <= GetLabelStartDepth()) return StringStartDepth + s.length(); // StringStartDepth + s.length() = string's depth. It must be greater // than the label's start depth, otherwise there's an error. // Example: If StringStartDepth = 0, s.length() = 1, then string's depth = 1. // If the parent node's depth = 1, it means the comparison should belong // to the parent node's edge (the first character in the tree), not this one. unsigned int startpos = GetLabelStartDepth() - StringStartDepth; // startpos determines the starting position of the string, to compare with // the label. // if StringStartDepth = 0, and the Label's Start Depth = 0 // (it means we're comparing an edge that goes from the root node to // the currentnode). So we should start comparison at string's position 0-0 = 0. // Now let's compare the strings and find the first difference. const wxString& the_label = GetActualLabel(tree); size_t i,i_limit; i_limit = s.length() - startpos; if (i_limit > m_LabelLen) i_limit = m_LabelLen; for (i = 0; i < i_limit; i++) { if (the_label[m_LabelStart+i]!=s[startpos+i]) break; } return GetLabelStartDepth() + i; }