Example #1
0
void ReplaceWord(wxString& str, const wxString& replaceFrom, const wxString& replaceTo, bool numbers = false)
{
	unsigned int i = 0;
	unsigned int l = replaceFrom.Length();
	while (i < str.Length()) {
		if (str.Mid(i, l) == replaceFrom) {
			if ((i == 0 || IsWordSeparator(str.GetChar(i-1))) &&
				((i == str.Length() - l || IsWordSeparator(str.GetChar(i+l))) ||
					(numbers && IsDigit(str.GetChar(i+l))))) {
				str.replace(i, l, replaceTo);
			}
			i += replaceTo.Length() - 1;
		}
		i++;
	}
}
Example #2
0
void CFileDetailDialog::OnBnClickedButtonStrip(wxCommandEvent& WXUNUSED(evt))
{
	wxString filename;
	filename = CastChild(IDC_FILENAME, wxTextCtrl)->GetValue();
	
	int extpos = filename.Find('.', true);
	wxString ext;
	if (extpos > 0) {
		// get the extension - we do not modify it except make it lowercase
		ext = filename.Mid(extpos);
		ext.MakeLower();
		// get rid of extension and replace . with space
		filename.Truncate(extpos);
		filename.Replace(wxT("."),wxT(" "));
	}

	// Replace Space-holders with Spaces
	filename.Replace(wxT("_"),wxT(" "));
	filename.Replace(wxT("%20"),wxT(" "));

	// Some additional formatting
	filename.Replace(wxT("hYPNOTiC"), wxEmptyString);
	filename.MakeLower();
	filename.Replace(wxT("xxx"), wxT("XXX"));
//	filename.Replace(wxT("xdmnx"), wxEmptyString);
//	filename.Replace(wxT("pmp"), wxEmptyString);
//	filename.Replace(wxT("dws"), wxEmptyString);
	filename.Replace(wxT("www pornreactor com"), wxEmptyString);
	filename.Replace(wxT("sharereactor"), wxEmptyString);
	filename.Replace(wxT("found via www filedonkey com"), wxEmptyString);
	filename.Replace(wxT("deviance"), wxEmptyString);
	filename.Replace(wxT("adunanza"), wxEmptyString);
	filename.Replace(wxT("-ftv"), wxEmptyString);
	filename.Replace(wxT("flt"), wxEmptyString);
	filename.Replace(wxT("[]"), wxEmptyString);
	filename.Replace(wxT("()"), wxEmptyString);

	// Change CD, CD#, VCD{,#}, DVD{,#}, ISO, PC to uppercase
	ReplaceWord(filename, wxT("cd"), wxT("CD"), true);
	ReplaceWord(filename, wxT("vcd"), wxT("VCD"), true);
	ReplaceWord(filename, wxT("dvd"), wxT("DVD"), true);
	ReplaceWord(filename, wxT("iso"), wxT("ISO"), false);
	ReplaceWord(filename, wxT("pc"), wxT("PC"), false);

	// Make leading Caps
	// and delete 1+ spaces
	if (filename.Length()>1)
	{
		bool last_char_space = true;
		bool last_char_wordseparator = true;
		unsigned int i = 0;

		do {
			wxChar c = filename.GetChar(i);
			if (c == ' ') {
				if (last_char_space) {
					filename.Remove(i, 1);
					i--;
				} else {
					last_char_space = true;
				}
			} else if (c == '.') {
				if (last_char_space && i > 0) {
					i--;
					filename.Remove(i, 1);
				}
				last_char_space = false;
			} else {
				if (last_char_wordseparator) {
					wxString tempStr(c);
					tempStr.MakeUpper();
					filename.SetChar(i, tempStr.GetChar(0));
					last_char_space = false;
				}
			}
			last_char_wordseparator = IsWordSeparator(c);
			i++;
		} while (i < filename.Length());

		if (last_char_space && i > 0) {
			filename.Remove(i-1, 1);
		}
	}

	// should stay lowercase
	ReplaceWord(filename, wxT("By"), wxT("by"));

	// re-add extension
	filename += ext;

	setValueForFilenameTextEdit(filename);
}
Example #3
0
void Font::SplitTextToStrings(const WideString & text, const Vector2 & targetRectSize, Vector<WideString> & resultVector)
{
	int32 targetWidth = (int32)(targetRectSize.dx * Core::GetVirtualToPhysicalFactor());

	enum
	{
		SKIP = 0,
		GOODCHAR,	// all characters we like (symbols, special chars, except \n and space
		FINISH,	// process last line
		EXIT,
	};

    // Yuri Coder, 2013/12/10. Replace "\n" occurrences (two chars) to '\n' (one char) is done by Yaml parser,
    // so appropriate code (state NEXTLINE)is removed from here. See please MOBWOT-6499.

    
    SeparatorPositions separator;
    
	resultVector.clear();
	int state = SKIP;
	int totalSize = (int)text.length();
	
	Vector<float32> sizes;
	GetStringSize(text, &sizes);
    if(sizes.size() == 0)
    {
        return;
    }

    bool wasSeparator = false;
	
	for(int pos = 0; state != EXIT; pos++)
	{
		char16 t = 0;
		if(pos < totalSize)
		{
			t = text[pos];
		}
        bool isSeparator = IsWordSeparator(t);

		switch (state) 
		{
			case SKIP:
				if (t == 0){ state = FINISH; break; } // if end of string process FINISH state and exit
				else if (IsSpace(t))break; // if space continue with the same state
                else if(IsLineEnd(t))
				{
					// this block is copied from case NEXTLINE: if(t == 'n')
					// unlike in NEXTLINE where we ignore 2 symbols, here we ignore only one
					// so last position is pos instead of (pos-1)
					if (separator.IsLineInitialized()) // if we already have something in current line we add to result
					{
                        AddCurrentLine(text, pos, separator, resultVector);
					}else
					{
						resultVector.push_back(L""); // here we add empty line if there was no characters in current line
					}
					state = SKIP; //always switch to SKIP because we do not know here what will be next
					break;
				}
				else // everything else is good characters
				{
					state = GOODCHAR;
					separator.lastWordStart = pos;
					separator.lastWordEnd = pos;
					if (!separator.IsLineInitialized()) separator.currentLineStart = pos;
				}
				break;
			case GOODCHAR:
                {
                    
                    if(IsSpace(t) || IsLineEnd(t) || t == 0 || (wasSeparator && !isSeparator)) // if we've found any possible separator process current line
				    {
                    
                        //calculate current line width
					    float32 currentLineWidth = 0;

					    int32 startPos = (separator.IsLineInitialized()) ? separator.currentLineStart : 0;
					    for (int i = startPos; i < pos ; i++)
					    {
						    currentLineWidth += sizes[i];
					    }
                    
                        if((currentLineWidth < targetWidth) || ((IsSpace(t) || isSeparator) && 0 == targetWidth))
                        {   // pos could be the end of line. We need to save it
                            if(IsLineEnd(t) || t == 0)
                            {
                                AddCurrentLine(text, pos, separator, resultVector);
                            }
                            else
                            {
                                separator.currentLineEnd = pos;
                                separator.lastWordEnd = pos;
                            }
                        }
                        else if(currentLineWidth == targetWidth)
                        {   // line fit all available space
                            DVASSERT(pos > separator.currentLineStart);
                        
                            AddCurrentLine(text, pos, separator, resultVector);
                        }
                        else
                        {   //currentLineWidth > targetWidth
                            int32 currentLineLength = separator.currentLineEnd - separator.currentLineStart;
                            if((currentLineLength > 0))
                            {   // use previous position of separator to split text
                            
                                pos = separator.currentLineEnd;
                                AddCurrentLine(text, pos, separator, resultVector);
                                t = 0;
                                if(pos + 1 < totalSize)
		                        {
			                        t = text[pos + 1];
		                        }
                                if(IsSpace(t) || IsLineEnd(t) || t == 0)
                                {
							        state = SKIP;
                                }
                                else
                                {
                                    state = GOODCHAR;
					                separator.lastWordStart = pos;
					                separator.lastWordEnd = pos;
					                if (!separator.IsLineInitialized()) separator.currentLineStart = pos;
                                }
							    break;
                            }
                            else if(pos)
                            {   // truncate text by symbol for very long word
                                if(0 == targetWidth)
                                {
                                    AddCurrentLine(text, pos, separator, resultVector);
                                }
                                else
                                {
								    int32 endPos = (separator.IsLineInitialized()) ? separator.currentLineStart : 0;
                                    for (int i = pos-1; i >= endPos; --i)
                                    {
                                        currentLineWidth -= sizes[i];
                                        if(currentLineWidth <= targetWidth)
                                        {
                                            separator.currentLineEnd = i;
                                            int32 currentLineLength = separator.currentLineEnd - separator.currentLineStart;
                                            if((currentLineLength > 0)) // use previous position of separator to split text
                                            {
                                                pos = separator.currentLineEnd-1;
                                            
                                                AddCurrentLine(text, separator.currentLineEnd, separator, resultVector);
                                            }
                                        
                                            break;
                                        }
                                    
                                        DVASSERT(i);
                                    }
                                }

							    state = SKIP;
							    break;
                            }
                            else
                            {
                                DVASSERT(0);
                            }
                        }
                    }

					if (IsSpace(t) || IsLineEnd(t)) state = SKIP; // if cur char is space go to skip
					else if (t == 0) state = FINISH;
                    else if(wasSeparator && !isSeparator)
                    {
                        // good char after separator
					    separator.lastWordStart = pos;
					    separator.lastWordEnd = pos;
					    if (!separator.IsLineInitialized()) separator.currentLineStart = pos;
                    }
                }
				break;
			case FINISH:
				if (separator.IsLineInitialized()) // we check if we have something left in currentline and add this line to results
				{
                    DVASSERT(separator.currentLineEnd > separator.currentLineStart);
                    AddCurrentLine(text, separator.currentLineEnd, separator, resultVector);
				}
				state = EXIT; // always exit from here
				break;
		};
        wasSeparator = isSeparator;
	};
}