示例#1
0
/* extract the file name less the extension given a <path> */
char* fileNameLessExtension(char* path)
{
	int beginIndex = 0, endIndex = 0;
	
	beginIndex = lastIndexOf(path, '\\');
	
	if (beginIndex != 0)
	{
		beginIndex++;
	}
	
	endIndex = lastIndexOf(path, '.');
	
	return substring(path, beginIndex, endIndex);
}
void CppHelperPluginView::includeFileDblClickedFromList(const QModelIndex& index)
{
    assert(
        "Active view supposed to be valid at this point! Am I wrong?"
      && mainWindow()->activeView()
      );

    auto filename = m_includes_list_model->itemFromIndex(index)->text();
    const auto pos = filename.lastIndexOf('[');
    const auto line = filename.mid(pos + 1, filename.lastIndexOf(']') - pos - 1).toInt(nullptr);
    filename.remove(pos, filename.size());
    dblClickOpenFile(std::move(filename));
    mainWindow()->activeView()->setCursorPosition({line, 0});
    mainWindow()->activeView()->setSelection({line, 0, line + 1, 0});
}
QVariant AnimationEditor::ImageTableModel::data(const QModelIndex &index, int role) const {
	if (role == Qt::DecorationRole || role == Qt::DisplayRole) {
		int r = index.row();
		int c = index.column();
		auto slide = m_model.Images[r];

		switch (c) {
		case 0:
		{
			auto img = slide.Image;
			if (!m_pixMaps.contains(slide.Image.toJson())) {
				m_pixMaps[img.toJson()] = SpriteSheetManager::getPixmap(img, m_projectPath);
			}
			return m_pixMaps[slide.Image.toJson()];
		}
		case 1:
		{
			auto spriteSheet = m_projectPath + slide.Image.SpriteSheet;
			spriteSheet = spriteSheet.mid(spriteSheet.lastIndexOf('/') + 1);
			spriteSheet = spriteSheet.mid(0, spriteSheet.size() - 5);
			return spriteSheet;
		}
		case 2:
			return slide.Interval;
		}
	}
	return QVariant();
}
示例#4
0
文件: Path.cpp 项目: terranpro/rct
const char * Path::extension() const
{
    const int dot = lastIndexOf('.');
    if (dot == -1 || dot + 1 == size())
        return 0;
    return constData() + dot + 1;
}
示例#5
0
文件: Path.cpp 项目: jmataraz/rct
const char * Path::fileName(int *len) const
{
    const int idx = lastIndexOf('/') + 1;
    if (len)
        *len = size() - idx;
    return constData() + idx;
}
示例#6
0
文件: main.c 项目: madmarks/SoftUni
/*
 * Problem 3. Last Occurrence of Character
 * 
 * Write a function that takes determines the position of the rightmost 
 * occurrence of a character ch in a string str. If no such character exists, 
 * the function should return -1.
 */
int main() 
{
    char ch;
    char str[STRING_LENGTH_MAX];
    
    printf("Input string: ");
    fgets(str, STRING_LENGTH_MAX, stdin);
    
    int length = strlen(str);
    if(str[length - 1] == '\n')
        str[length - 1] = '\0';
    
    printf("Input char: ");
    scanf("%c", &ch);
    
    int lastIndex = lastIndexOf(str, length, ch);
    
    if(lastIndex != -1)
    {
        printf("\nPosition of the rightmost occurrence of \'%c\' is: %i\n",
            ch, lastIndex);
    }
    else
    {
        printf("\n-1 : character \'%c\' does not exist in the given string\n", ch);
    }
    
    // Test data:
    //
    // Sir Stanley Royce
    // AAAAAAA
    // Do NOT run this command:  :(){ :|: & };:

    return (EXIT_SUCCESS);
}
KTextEditor::Range IncludeHelperCompletionModel::completionRange(
    KTextEditor::View* view
  , const KTextEditor::Cursor& position
  )
{
    kDebug(DEBUG_AREA) << "cursor: " << position;
    auto line = view->document()->line(position.line());
    auto r = parseIncludeDirective(line, false);
    if (r.m_range.isValid())
    {
        auto start = line.lastIndexOf('/', r.m_range.end().column() - 1);
        kDebug(DEBUG_AREA) << "init start=" << start;
        start = start == -1 ? r.m_range.start().column() : start + 1;
        kDebug(DEBUG_AREA) << "fixed start=" << start;
        KTextEditor::Range range(
            position.line()
          , start
          , position.line()
          , r.m_range.end().column()
          );
        kDebug(DEBUG_AREA) << "selected range: " << range;
        return range;
    }
    kDebug(DEBUG_AREA) << "default select";
#if 0
    return KTextEditor::Range();
#else
    return KTextEditor::CodeCompletionModelControllerInterface3::completionRange(view, position);
#endif
}
示例#8
0
文件: Utils.cpp 项目: yalp/MeMoPlayer
bool MultiPathFile::addPath (char * path, bool atEnd) {
    if (!s_follow) return false;
    //fprintf (myStderr, ">>> MultiPathFile::addPath: adding from %s\n", path);
    int i = lastIndexOf (path, '/');
    if (i >= 0) {
        int cd = open (".", O_RDONLY);
        path [i] = '\0';
        chdir (path);
        path [i] = '/';
        char * tmp = (char *)malloc (4096);
        char * cwd = getcwd (tmp, 4096);
        //fprintf (myStderr, ">>> MultiPathFile::addPath: adding  %s\n", tmp);
        fchdir (cd);
        close(cd);
        if (atEnd && s_path != NULL) {
            Link * last = s_path;
            while (last->next != NULL) {
                last = last->next;
            }
            last->next = new Link (cwd, NULL);
        } else {
            s_path = new Link (cwd, s_path);
        }
        return true;
    }
    return false;
}
	void MsgEditAutocompleter::complete ()
	{
		auto cursor = MsgEdit_->textCursor ();

		int cursorPosition = cursor.position ();
		int pos = -1;

		auto text = MsgEdit_->toPlainText ();

		if (AvailableNickList_.isEmpty ())
		{
			pos = text.lastIndexOf (' ', cursorPosition ? cursorPosition - 1 : 0);
			LastSpacePosition_ = pos;
		}
		else
			pos = LastSpacePosition_;

		if (NickFirstPart_.isNull ())
			NickFirstPart_ = cursorPosition ?
					text.mid (pos + 1, cursorPosition - pos - 1) :
					"";

		const auto& completions = GetPossibleCompletions (NickFirstPart_, pos);
		const auto& replacement = GetNickFromState (completions);
		if (replacement.NewText_.isEmpty ())
			return;

		text.replace (pos + 1, replacement.Length_, replacement.NewText_);
		++CurrentNickIndex_;

		MsgEdit_->setPlainText (text);
		cursor.setPosition (pos + 1 + replacement.NewText_.size ());
		MsgEdit_->setTextCursor (cursor);
	}
示例#10
0
	bool String::hasSubfix(const char* subfix){
		const int64_t len =strlen(subfix);
		if(len <= 0){
			return true;
		}
		const int64_t idx =lastIndexOf(subfix);
		return idx>=0 ? (idx+len) == m_length : false;
	}
示例#11
0
文件: Utils.cpp 项目: yalp/MeMoPlayer
/**
 * Removes a path added by addPath()
 */
void MultiPathFile::removePath (char * path) {
    if (!s_follow) return;
    int i = lastIndexOf (path, '/');
    if (i >= 0 && s_path != NULL) {
        path [i] = '\0';
        s_path = s_path->remove(path);
        path [i] = '/';
    }
}
示例#12
0
bool ArrayList<T*>::remove(T *element)
{
    int index;
    if ((index = lastIndexOf(element)) >=0){
        remove(index);
        return true;
    }
    return false;
}
示例#13
0
 void ArrayTests::runTests()
 {
   create();
   subscript();
   lastIndexOf();
   removeAt();
   grow();
   truncate();
 }
示例#14
0
// Calls function: subString(int fromIndex, int charCount)
const str& str::subString(char fromFirstChar, char toLastChar)
{
    const char fi[] = {fromFirstChar, 0x00};
    const char li[] = {toLastChar, 0x00};
    const int firstIndex = firstIndexOf(fi);
    const int lastIndex  =  lastIndexOf(li);

    return subString(firstIndex, lastIndex - firstIndex + 1);
}
示例#15
0
 QString BuildModel::__retrievePackage( ProjectItem *item ) {
   auto path = item->path().replace(".o3prm", "", Qt::CaseInsensitive);
   int count = path.count("/");
   if ( path.count("/") > 0 ) {
     int last = path.lastIndexOf("/");
     path.truncate(last);
     return path.replace("/", ".");
   }
   return QString("");
 }
int
RAbstractStringRef::lastIndexOf(char ch) const
{
  if(length() == 0)
  {
    return -1;
  }

  return lastIndexOf(ch, length() - 1);
}
示例#17
0
bool str::replaceLast(const char* pFind, const char* pWith)
{
    const int findIndex = lastIndexOf(pFind);
    if(findIndex != mInvalidIndex)
    {
        eraseAfter(findIndex, strlen(pFind));
        insertAt(findIndex, pWith);
        return true;
    }
    return false;
}
示例#18
0
文件: Path.cpp 项目: emdeesee/rct
const char * Path::fileName(int *len) const
{
    const int length = size();
    int idx = 0;
    if (length > 1)
        idx = lastIndexOf('/', length - 2) + 1;

    if (len)
        *len = size() - idx;
    return constData() + idx;
}
示例#19
0
QString FileNameTextEdit::textUnderCursor() const
{
    QTextCursor tc = textCursor();

    tc.select(QTextCursor::BlockUnderCursor);

    auto block = tc.selectedText();
    int i = block.lastIndexOf("<");
    int i2 = block.lastIndexOf(">");
    
    if (i < 0 || ( i < i2))
        return "";
    
    i = block.length() - i;

    tc.setPosition(tc.position());
    tc.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, i);

    tc.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, i);
    return tc.selectedText();
}
示例#20
0
QString SnapshotWidget::defaultFilename() const {
    const QString vp = vpXYRadio.isChecked() ? "XY" :
                   vpXZRadio.isChecked() ? "XZ" :
                   vpZYRadio.isChecked() ? "ZY" :
                   vpArbRadio.isChecked() ? "Arb" :
                                           "3D";
    auto pos = &state->viewerState->currentPosition;
    auto annotationName = Session::singleton().annotationFilename;
    annotationName.remove(0, annotationName.lastIndexOf("/") + 1); // remove directory structure from name
    annotationName.chop(annotationName.endsWith(".k.zip") ? 6 : /* .nml */ 4); // remove file type
    return QString("%1_%2_%3_%4_%5.png").arg(vp).arg(pos->x).arg(pos->y).arg(pos->z).arg(annotationName.isEmpty() ? state->name : annotationName);
}
示例#21
0
文件: Path.cpp 项目: emdeesee/rct
String Path::name() const
{
    if (endsWith('/')) {
        const int secondLastSlash = lastIndexOf('/', size() - 2);
        if (secondLastSlash != -1) {
            return mid(secondLastSlash + 1, size() - secondLastSlash - 2);
        }
        return String();
    } else {
        return fileName();
    }
}
示例#22
0
ModelBaker::ModelBaker(const QUrl& inputModelURL, const QString& bakedOutputDirectory, const QString& originalOutputDirectory, bool hasBeenBaked) :
    _modelURL(inputModelURL),
    _bakedOutputDir(bakedOutputDirectory),
    _originalOutputDir(originalOutputDirectory),
    _hasBeenBaked(hasBeenBaked)
{
    auto bakedFilename = _modelURL.fileName();
    if (!hasBeenBaked) {
        bakedFilename = bakedFilename.left(bakedFilename.lastIndexOf('.'));
        bakedFilename += BAKED_FBX_EXTENSION;
    }
    _bakedModelURL = _bakedOutputDir + "/" + bakedFilename;
}
示例#23
0
char* get_root()
{
    int bufsize = 1023;
    char *buf = calloc(bufsize, sizeof(char));
    char *root = calloc(bufsize, sizeof(char));
    get_exec_path(buf, bufsize);
    int index = lastIndexOf(buf, "/");
    substr(root, bufsize, buf, index);
    strcat(root, "/../../../html");
    log_info("Setting root: %s", root);
    free(buf);
    return root;
}
示例#24
0
/*
extract a specified directory path given the level
NOTE: the level can be positive or negative
*/
char* extractDirectory(char* path, int level)
{
	/* length of path string */
	int length = strlen(path);
	
	/* current directory level */
	int currentLevel = 0;
	
	/* used to store directory separator index */
	int targetDirectorySeparatorIndex = 0;
	
	/* iterator */
	int i;
	
	/* iterate through the directory levels */
	for (i=0; i<abs(level); i++)
	{
		/* negative level */
		if (level < 0)
		{
			targetDirectorySeparatorIndex = lastIndexOf(path,'\\');
			path = substring(path, 0, targetDirectorySeparatorIndex);
		}
		
		/* positive level */
		else
		{
			/* first iteration - special case */
			if (targetDirectorySeparatorIndex == 0)
			{
				targetDirectorySeparatorIndex = indexOfWithStart(path,'\\', targetDirectorySeparatorIndex);
			}
			
			/* all other iterations - must add 1*/
			else
			{
				targetDirectorySeparatorIndex = indexOfWithStart(path,'\\', targetDirectorySeparatorIndex + 1);
			}
		}
	}
	
	/* if a positive level, must extract the directory string now */
	if (level > 0)
	{
		path = substring(path, 0, targetDirectorySeparatorIndex);
	}
	
	return path;
}
示例#25
0
文件: Utils.cpp 项目: yalp/MeMoPlayer
void MultiPathFile::addMultiplePaths (char * paths) {
    //fprintf (myStderr, ">>> MultiPathFile::addMultiplePaths: adding from %s\n", paths);
    char cwdTmp[4096];
    int cd = open (".", O_RDONLY);
    char * tmp = strdup(paths);
    int i = lastIndexOf(tmp,';');
    while (i>=0) {
        char * p = tmp+i+1;
        tmp[i] = '\0';
        chdir (p);
        getcwd (cwdTmp, 4096);
        fchdir (cd);
        //fprintf (myStderr, ">>> MultiPathFile::addMultiplePaths: add %s\n", cwdTmp);
        s_path = new Link(strdup(cwdTmp), s_path);
        i = lastIndexOf(tmp,';');
    }
    chdir (tmp);
    free (tmp);
    getcwd (cwdTmp, 4096);
    fchdir (cd);
    //fprintf (myStderr, ">>> MultiPathFile::addMultiplePaths: add %s\n", cwdTmp);
    s_path = new Link(strdup(cwdTmp), s_path);
    close(cd);
}
示例#26
0
TextureBaker::TextureBaker(const QUrl& textureURL, image::TextureUsage::Type textureType,
                           const QDir& outputDirectory, const QString& bakedFilename,
                           const QByteArray& textureContent) :
    _textureURL(textureURL),
    _originalTexture(textureContent),
    _textureType(textureType),
    _outputDirectory(outputDirectory),
    _bakedTextureFileName(bakedFilename)
{
    if (bakedFilename.isEmpty()) {
        // figure out the baked texture filename
        auto originalFilename = textureURL.fileName();
        _bakedTextureFileName = originalFilename.left(originalFilename.lastIndexOf('.')) + BAKED_TEXTURE_EXT;
    }
}
示例#27
0
void String::replace(const String &find, const String &replace)
{
    if ( (len == 0) || (find.len == 0) ) {
        return;
    }
    int  diff      = replace.len - find.len;
    char *readFrom = buffer;
    char *foundAt;
    if ( diff == 0 ) {
        while ( ( foundAt = strstr(readFrom, find.buffer) ) != NULL ) {
            memcpy(foundAt, replace.buffer, replace.len);
            readFrom = foundAt + replace.len;
        }
    } else if ( diff < 0 ) {
        char *writeTo = buffer;
        while ( ( foundAt = strstr(readFrom, find.buffer) ) != NULL ) {
            unsigned int n = foundAt - readFrom;
            memcpy(writeTo, readFrom,       n);
            writeTo += n;
            memcpy(writeTo, replace.buffer, replace.len);
            writeTo += replace.len;
            readFrom = foundAt + find.len;
            len     += diff;
        }
        strcpy(writeTo, readFrom);
    } else {
        unsigned int size = len; // compute size needed for result
        while ( ( foundAt = strstr(readFrom, find.buffer) ) != NULL ) {
            readFrom = foundAt + find.len;
            size    += diff;
        }
        if ( size == len ) {
            return;
        }
        if ( (size > capacity) && !changeBuffer(size) ) {
            return; // XXX: tell user!
        }
        int index = len - 1;
        while ( index >= 0 && ( index = lastIndexOf(find, index) ) >= 0 ) {
            readFrom = buffer + index + find.len;
            memmove( readFrom + diff, readFrom, len - (readFrom - buffer) );
            len        += diff;
            buffer[len] = 0;
            memcpy(buffer + index, replace.buffer, replace.len);
            index--;
        }
    }
}
示例#28
0
bool str::checksum_Verify()
{
    bool checksumIsValid = false;
    const int checkSumIndex = lastIndexOf(":");

    if(mInvalidIndex != checkSumIndex)
    {
        mpStr[checkSumIndex] = '\0';
        const unsigned int actualChecksum = hexStrDigitsToInt(mpStr+checkSumIndex+1);
        const unsigned int expectedChecksum = checksum_Get();
        checksumIsValid = (actualChecksum == expectedChecksum);
        mpStr[checkSumIndex] = ':';
    }

    return checksumIsValid;
}
示例#29
0
void compile (char * inName, char * dir, MediaList &includeMedia, bool verbose) {
    char * orgName = inName;

    MultiPathFile::addPath (inName, true); // main path is set as last path
    int cd = open (".", O_RDONLY);
    int i = lastIndexOf (inName, '/');
    if (i >= 0) {
        inName [i] = '\0';
        chdir (inName);
        //MultiPathFile::addPath (inName);
        inName += i+1;
    }

    char * binName = strdup (inName);
    strcpy (binName+strlen(binName)-3, "m4m");
    printf ("compile %s -> %s/%s\n", orgName, dir, binName);

    Scene scene (binName, verbose);

    FILE * in = fopen (inName, "rb");
    if (in == NULL) {
        fprintf (myStderr, "cannot open %s", inName);
        exit (1);
    }
    printf (">> Compiling scene %s\n", inName);
    scene.parse (inName, in, verbose);

    fchdir (cd);

    char * outName = (char *)malloc (strlen (binName)+strlen(dir)+2);
    sprintf (outName, "%s/%s", dir, binName);
    FILE * out = fopen (outName, "wb");
    if (out == NULL) {
        fprintf (myStderr, "Cannot open %s for writing, please check if path exists\n", outName);
        exit (1);
    }
    int total = includeMedia.dump (out);
    total += scene.encode (out, verbose);
    total += FontManager::dumpAll (execPath, out);
    write (out, 0xFFFF); // final end of file
    printf ("<< End of scene %s [%d B]\n", inName, total);

    fclose (in);
    fclose (out);

    LocaleManager::checkMissingTranslations();
}
示例#30
0
文件: JSBaker.cpp 项目: ZappoMan/hifi
void JSBaker::bake() {
    qCDebug(js_baking) << "JS Baker " << _jsURL << "bake starting";

    // Import file to start baking
    QFile jsFile(_jsURL.toLocalFile());
    if (!jsFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        handleError("Error opening " + _jsURL.fileName() + " for reading");
        return;
    }

    // Read file into an array
    QByteArray inputJS = jsFile.readAll();
    QByteArray outputJS;

    // Call baking on inputJS and store result in outputJS 
    bool success = bakeJS(inputJS, outputJS);
    if (!success) {
        qCDebug(js_baking) << "Bake Failed";
        handleError("Unterminated multi-line comment");
        return;
    }

    // Bake Successful. Export the file
    auto fileName = _jsURL.fileName();
    auto baseName = fileName.left(fileName.lastIndexOf('.'));
    auto bakedFilename = baseName + BAKED_JS_EXTENSION;

    _bakedJSFilePath = _bakedOutputDir + "/" + bakedFilename;

    QFile bakedFile;
    bakedFile.setFileName(_bakedJSFilePath);
    if (!bakedFile.open(QIODevice::WriteOnly)) {
        handleError("Error opening " + _bakedJSFilePath + " for writing");
        return;
    }

    bakedFile.write(outputJS);

    // Export successful
    _outputFiles.push_back(_bakedJSFilePath);
    qCDebug(js_baking) << "Exported" << _jsURL << "minified to" << _bakedJSFilePath;

    // emit signal to indicate the JS baking is finished
    emit finished();
}