コード例 #1
0
ファイル: jpath.cpp プロジェクト: joshuamaurice/jjmake
jjm::Utf8String jjm::Path::getFileName() const
{
    Utf8String result; 
    pair<size_t, size_t> const lastComponent = getPrevComponent(path, path.size()); 
    result.append(path.data() + lastComponent.first, path.data() + lastComponent.second); 
    return result; 
}
コード例 #2
0
ファイル: codecompleter.cpp プロジェクト: choenig/qt-creator
ClangCodeCompleteResults CodeCompleter::completeSmartPointerCreation(uint line,
                                                                     uint column,
                                                                     int funcNameStartLine,
                                                                     int funcNameStartColumn)
{
    if (column <= 1 || funcNameStartLine == -1)
        return ClangCodeCompleteResults();

    UnsavedFile &file = unsavedFiles.unsavedFile(translationUnit.filePath());
    if (!file.hasCharacterAt(line, column - 1, '('))
        return ClangCodeCompleteResults();

    bool ok;
    const uint startPos = file.toUtf8Position(funcNameStartLine, funcNameStartColumn, &ok);
    const uint endPos = file.toUtf8Position(line, column - 1, &ok);

    Utf8String content = file.fileContent();
    const QString oldName = content.mid(startPos, endPos - startPos);
    const QString updatedName = tweakName(oldName);
    if (updatedName.isEmpty())
        return ClangCodeCompleteResults();

    column += updatedName.length();
    file.replaceAt(endPos + 1, 0, updatedName);

    ClangCodeCompleteResults results = completeHelper(line, column);
    if (results.isEmpty()) {
        column -= updatedName.length();
        file.replaceAt(endPos + 1, updatedName.length(), QString());
    }
    return results;
}
コード例 #3
0
ファイル: utf8string.cpp プロジェクト: DuinoDu/qt-creator
bool operator<(const Utf8String &first, const Utf8String &second)
{
    if (first.byteSize() == second.byteSize())
        return first.byteArray < second.byteArray;

    return first.byteSize() < second.byteSize();
}
コード例 #4
0
const Utf8String ExtractFileNameNoExt(const Utf8String& fileName)
{
	Utf8String result = ExtractFileName(fileName);
	int Qpos = result.find_last_of('.');
	if(Qpos>=0) result = result.substr(0, Qpos);
	return result;
}
コード例 #5
0
ファイル: String.cpp プロジェクト: klinki/MI-RUN
			String::String(Utf8String & str, Class * classPtr): ObjectHeader(classPtr)
			{
				this->dataLength = str.bytes();
				this->hash = str.getHash();
				this->stringLength = str.length();

				memcpy(this->data, str.toAsciiString(), str.bytes());
			}
コード例 #6
0
bool PutFileContents(const Utf8String& utf8Filename, const Utf8String& content)
{
	FILE *stream = fopen_utf8(utf8Filename.c_str(), "wb");
	if(!stream) return false;
	fwrite(content.c_str(), content.length(),1, stream);
	fclose(stream);
	return true;
}
コード例 #7
0
Utf8String StrReplace(Utf8String text, Utf8String s, Utf8String d)
{
    for(int index=0; index=text.find(s, index), index!=std::string::npos;)
	{
		text.replace(index, s.length(), d);
		index += d.length();
	}
	return text;
}
コード例 #8
0
SourceRangeContainer FollowSymbol::followSymbol(CXTranslationUnit tu,
                                                const Cursor &fullCursor,
                                                uint line,
                                                uint column)
{
    std::unique_ptr<Tokens> tokens(new Tokens(fullCursor));

    if (!tokens->tokenCount)
        tokens.reset(new Tokens(tu));

    if (!tokens->tokenCount)
        return SourceRangeContainer();

    QVector<CXCursor> cursors(static_cast<int>(tokens->tokenCount));
    clang_annotateTokens(tu, tokens->data, tokens->tokenCount, cursors.data());
    int tokenIndex = getTokenIndex(tu, *tokens, line, column);
    QTC_ASSERT(tokenIndex >= 0, return SourceRangeContainer());

    const Utf8String tokenSpelling = ClangString(
                clang_getTokenSpelling(tu, tokens->data[tokenIndex]));
    if (tokenSpelling.isEmpty())
        return SourceRangeContainer();

    Cursor cursor{cursors[tokenIndex]};

    if (cursor.kind() == CXCursor_InclusionDirective) {
        CXFile file = clang_getIncludedFile(cursors[tokenIndex]);
        const ClangString filename(clang_getFileName(file));
        const SourceLocation loc(tu, filename, 1, 1);
        return SourceRange(loc, loc);
    }

    // For definitions we can always find a declaration in current TU
    if (cursor.isDefinition())
        return extractMatchingTokenRange(cursor.canonical(), tokenSpelling);

    if (!cursor.isDeclaration()) {
        // This is the symbol usage
        // We want to return definition
        cursor = cursor.referenced();
        if (cursor.isNull() || !cursor.isDefinition()) {
            // We can't find definition in this TU
            return SourceRangeContainer();
        }
        return extractMatchingTokenRange(cursor, tokenSpelling);
    }

    cursor = cursor.definition();
    // If we are able to find a definition in current TU
    if (!cursor.isNull())
        return extractMatchingTokenRange(cursor, tokenSpelling);

    return SourceRangeContainer();
}
コード例 #9
0
const Utf8String ExtractFilePath(const Utf8String& fileName)
{
	int i, len = fileName.length();
	for(i = len-1; i >= 0; i--)
	{
		if(fileName[i] == '\\' || fileName[i]=='/')
		{
			return fileName.substr(0, i+1);
		}
			
	}
	return "";
}
コード例 #10
0
ファイル: codecompleter.cpp プロジェクト: choenig/qt-creator
ClangCodeCompleteResults CodeCompleter::completeHelper(uint line, uint column)
{
    const Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
    UnsavedFilesShallowArguments unsaved = unsavedFiles.shallowArguments();

    return clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
                                nativeFilePath.constData(),
                                line,
                                column,
                                unsaved.data(),
                                unsaved.count(),
                                defaultOptions());
}
コード例 #11
0
Utf8String ExtractFileName(const Utf8String fileName)
{
		Utf8String temp = fileName;
		int Qpos = temp.find_last_of('?');
		if(Qpos>=0) temp = temp.substr(0, Qpos-1);
		int i,len = temp.length();
		for(i=len-1; i>=0; i--)
		{
			if(temp[i] == '\\' || temp[i]=='/')
				break;
		}
		return temp.substr(i+1);
}
コード例 #12
0
Utf8String ExtractFileExt(const Utf8String fileName)
{
	int nLen = fileName.length();

	Utf8String result;
	for( int i=nLen-1; i>=0; i-- )
	{
		if(fileName[i] == '.')
		{
			result = fileName.substr(i + 1);
			break;
		}
		else if(fileName[i] == '\\' || fileName[i] == '/') break;
	}
	return result;
}
コード例 #13
0
void CompletionChunksToTextConverter::parseText(const Utf8String &text)
{
    if (canAddSpace()
            && m_previousCodeCompletionChunk.kind() == ClangBackEnd::CodeCompletionChunk::RightBrace) {
        m_text += QChar(QChar::Space);
    }

    m_text += text.toString();
}
コード例 #14
0
ファイル: XMLWriter.cpp プロジェクト: Microsoft/pal
/*
**==============================================================================
**
**  Change the stored text for this element to one that has characters encoded
**  for output
**
**==============================================================================
*/
void CXElement::PutText(Utf8String& sOut, Utf8String& TextIn)
{
    if (!TextIn.Empty())
    {
        // Encode each character of the input string and add it to the output
        // string.
        Utf8String replacementString;
        Utf8String::Iterator start = TextIn.Begin();
        Utf8String::Iterator end = TextIn.End();
        for (; start != end; ++start)
        {
            Utf8String encodedStr;
            EncodeChar (*start, encodedStr);
            replacementString.Append(encodedStr);
        }

        sOut += replacementString;
    }

}
コード例 #15
0
ファイル: unsavedfile.cpp プロジェクト: DuinoDu/qt-creator
UnsavedFile::UnsavedFile(const Utf8String &filePath, const Utf8String &fileContent)
{
    char *cxUnsavedFilePath = new char[filePath.byteSize() + 1];
    char *cxUnsavedFileContent = new char[fileContent.byteSize() + 1];

    std::memcpy(cxUnsavedFilePath, filePath.constData(), filePath.byteSize() + 1);
    std::memcpy(cxUnsavedFileContent, fileContent.constData(), fileContent.byteSize() + 1);

    cxUnsavedFile = CXUnsavedFile{cxUnsavedFilePath,
                                  cxUnsavedFileContent,
                                  ulong(fileContent.byteSize())};
}
コード例 #16
0
SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit,
                               const Utf8String &filePath,
                               uint line,
                               uint column)
    : cxSourceLocation(clang_getLocation(cxTranslationUnit,
                                         clang_getFile(cxTranslationUnit,
                                                 filePath.constData()),
                                         line,
                                         column)),
      filePath_(filePath),
      line_(line),
      column_(column)
{
}
コード例 #17
0
bool ReadUtf8TextFile(Utf8String utf8Filename, Utf8String& data)
{
	FILE *stream = fopen_utf8(utf8Filename.c_str(), "rb");
	if(!stream) return false;
        long size = getFileSize(utf8Filename);
	unsigned char buf[3];
	fread(buf, 1, 3, stream);	


	if(buf[0] == 0xEF || buf[1] == 0xBB || buf[2] == 0xBF) // UTF8 Byte Order Mark (BOM)
	{	
		size -= 3;	
	}
	else if(buf[0] == 0xFF || buf[1] == 0xFE ) {
		// UTF-16LE encoding
		size -= 2;
		fseek( stream, 2L,  SEEK_SET );
		std::wstring res;
		int charCount = size/2;
		res.resize(charCount);
		size_t charsRead = fread(&res[0], 2, charCount, stream);	
		res[charsRead]=0;
		fclose(stream);
		data = WstringToUtf8(res);
		return true;
	} 
	else {
		// no BOM was found; seeking backward
		fseek( stream, 0L,  SEEK_SET );
	}
	data.resize(size + 1);
	size_t bytesRead = fread(&data[0], 1, size, stream);	
	data[bytesRead] = 0;
	fclose(stream);
	return true;
}
コード例 #18
0
ファイル: clangfilepath.cpp プロジェクト: choenig/qt-creator
Utf8String FilePath::toNativeSeparators(const Utf8String &pathName)
{
    const QByteArray pathNameAsByteArray = pathName.toByteArray();

    return Utf8String::fromUtf8(toNativeSeparatorsForQByteArray(pathNameAsByteArray));
}
コード例 #19
0
bool isOperator(CXCursorKind cxCursorKind, const Utf8String &name)
{
    return cxCursorKind == CXCursor_ConversionFunction
            || (cxCursorKind == CXCursor_CXXMethod
                && name.startsWith(Utf8StringLiteral("operator")));
}
コード例 #20
0
int SqliteStatement::bindingIndexForName(const Utf8String &name)
{
    return  sqlite3_bind_parameter_index(compiledStatement.get(), name.constData());
}
コード例 #21
0
ファイル: FileSystem.cpp プロジェクト: darcyg/Caramel
PathImpl::PathImpl( const Utf8String& path )
    #if defined( CARAMEL_SYSTEM_IS_WINDOWS )
    : boost::filesystem::path( path.ToWstring() )
    #else
    : boost::filesystem::path( path.ToString() )
コード例 #22
0
ファイル: XMLWriter.cpp プロジェクト: Microsoft/pal
/*
**==============================================================================
**
**  Starting with this element, build the output string that represents the entire
**  tree from this point down, building on the passed in string.  In other words,
**  the tree is traversed, and each element has its own save() method called.
**
**==============================================================================
*/
void CXElement::Save(Utf8String& sOut, bool bAddIndentation, Utf8String& sIndentation)
{
    // Output our start tag.
    if (bAddIndentation)
    {
        sOut += sIndentation;
    }

    sOut += open_bracket;
    sOut += m_sName;

    // Output all the attributes and close the start tag.
    for (size_t j = m_listAttribute.size();  j > 0;  j--)
    {
        sOut += u8_space + m_listAttribute[j - 1]->m_sName + equals_with_quote;
        PutText(sOut, m_listAttribute[j - 1]->m_sValue);
        sOut += ending_quote;
    }

    if (m_sName[0] != single_question) // XML_INSTRUCTION
    {
        // If this was an empty tag (just the name and attributes), and there were no children
        // then just close the tag.
        if (m_sText.Empty() && m_listChild.empty())
        {
            sOut += close_bracket_with_term;

            if (m_LineSeparatorsOn)
            {
                sOut += crlf;
            }

            return;
        }
        else
        {
            sOut += close_bracket;
        }
    }
    else
    {
        sOut += close_bracket_with_question;
    }

    if (!m_listChild.empty() && m_LineSeparatorsOn)
    {
        sOut += crlf;
    }

    // Output the text.
    // *** DO NOT put a line separator at the end of this data, or add indentation to the front.
    //     If you do so, and the data happens to be string data, you will be adding an
    //     extra \n\r to the output that will not be parsed out on input.  Changing the
    //     data is generally considered bad practice.
    if (!m_sText.Empty())
    {
        PutText (sOut, m_sText);
    }

    // Output all the child elements.
    std::vector<pCXElement>::iterator i;
    for (i = m_listChild.begin();  i != m_listChild.end();  i++)
    {
        pCXElement singleElement = *i;

        // Call the child element's save() method.
        sIndentation += four_spaces;
        singleElement->Save(sOut, bAddIndentation, sIndentation);
        sIndentation = sIndentation.substr(0, sIndentation.size() - 4);
    }

    if (m_sName[0] != single_question) // XML_INSTRUCTION
    {
        if (m_sText.Empty() && bAddIndentation)
        {
            sOut += sIndentation;
        }

        // Output the end tag.
        sOut += open_with_slash + m_sName + close_bracket;
    }

    // And close us up
    if (m_LineSeparatorsOn)
    {
        sOut += crlf;
    }
}
コード例 #23
0
ファイル: jpath.cpp プロジェクト: joshuamaurice/jjmake
jjm::Path  jjm::Path::getAbsolutePath() const
{
#ifdef _WIN32
    if (isEmpty())
        return *this; 

    pair<size_t, size_t> prefix = ::getPrefix(path); 
    bool const hasPrefix = prefix.first != prefix.second; 
    bool const isAbs = isAbsolute(); 

    if (hasPrefix && isAbs)
        return *this; 

    Utf8String root;
    if (hasPrefix)
        root.append(path.data() + prefix.first, path.data() + prefix.second); 
    if (isAbs)
        root.push_back(preferredSeparator); 
    else
        root.push_back('.'); 

    Utf8String root2 = invokeGetFullPathW(root); 
    Path root3(root2); 
    Path result = resolve(root3); 

    pair<size_t, size_t> resultPrefix = ::getPrefix(result.path); 
    if (resultPrefix.first == resultPrefix.second)
        JFATAL(0, path); 
    if ( ! result.isAbsolute())
        JFATAL(0, path); 
    if (result.isRootPath())
        return result; 

    vector<pair<size_t, size_t> > components; 
    for (pair<size_t, size_t> component(resultPrefix.second, resultPrefix.second); ; )
    {   component = ::getNextComponent(result.path, component.second); 
        if (component.first == component.second)
            break; 
        if (1 == component.second - component.first && result.path.data()[component.first] == '.')
            continue; 
        components.push_back(component); 
    }
    for (size_t i = 0; i < components.size(); )
    {   if (2 == components[i].second - components[i].first 
                && result.path.data()[components[i].first] == '.'
                && result.path.data()[components[i].first + 1] == '.')
        {   if (i == 0)
                return Path(); 
            components.erase(components.begin() + i - 1, components.begin() + i + 1); 
            --i; 
        }else
        {   ++i; 
        }
    }

    Path result2; 
    result2.path.append(result.path.data() + resultPrefix.first, result.path.data() + resultPrefix.second); 
    if (components.size() == 0)
        result2.path.push_back(preferredSeparator); 
    for (size_t i = 0; i < components.size(); ++i)
    {   result2.path.push_back(preferredSeparator); 
        result2.path.append(result.path.data() + components[i].first, result.path.data() + components[i].second); 
    }
    return result2; 
#else
    if (isEmpty())
        return *this; 

    pair<size_t, size_t> prefix = ::getPrefix(path); 
    if (prefix.first != prefix.second)
        throw std::runtime_error("jjm::Path::makeAbsolute() on POSIX systems does not support prefixes"); 
    if (isAbsolute() == false)
    {
        errno = 0; 
        UniquePtr<char*, jjm::InvokeFree> currentWorkingDirectory(::getcwd(0, 0)); 
        int const lastErrno = errno;

        if (currentWorkingDirectory.get() == 0)
        {   string msg = string() + "jjm::Path::getAbsolutePath() failed. "
                    + "::getcwd(0, 0) failed. "; 
            //TODO throw runtime_error(msg + "errno " + toDecStr(lastErrno) + " " + getErrnoName(lastErrno) + ".");
            throw runtime_error(msg + "errno " + toDecStr(lastErrno) + ".");
        }
        return resolve(Path(currentWorkingDirectory.get()));
    }
    return *this; 
#endif
}
コード例 #24
0
int64_t stringToint64_t(const Utf8String fileName)
{
    return zstrtoll(fileName.c_str(), 0, 10 , 0);
}
コード例 #25
0
ファイル: utf8string.cpp プロジェクト: choenig/qt-creator
QDebug operator<<(QDebug debug, const Utf8String &text)
{
    debug << text.constData();

    return debug;
}
コード例 #26
0
ファイル: utf8.cpp プロジェクト: zapster/cacao-travis
Utf8String Utf8String::from_utf8_slash_to_dot(Utf8String u) {
	return string_from_utf8<utf8::SlashToDot>(u.begin(), u.size());
}
コード例 #27
0
void CompletionChunksToTextConverter::parseResultType(const Utf8String &resultTypeText)
{
    if (m_addResultType)
        m_text += resultTypeText.toString() + QChar(QChar::Space);
}