//get the sequence image name in folder; void FeatureExtract::getImageStrings(string foldName, vector<string>& imgStrs) { DIR* dir = 0; struct dirent* s_dir = 0; struct stat st; char path[MaxStringLength] = ""; printf("folder: %s\n", foldName.c_str()); dir = opendir(foldName.c_str()); if(dir == NULL) return; while(s_dir = readdir(dir)) { if( strcmp(s_dir->d_name, ".")==0 || strcmp(s_dir->d_name, "..")==0) continue; //printf("d_name: %s\n", s_dir->d_name); if(s_dir->d_name[0] == '.') continue; stat(s_dir->d_name, &st); if(S_ISDIR(st.st_mode)) continue; if(!isImageFormat(s_dir->d_name)) continue; sprintf(path, "%s/%s", foldName.c_str(), s_dir->d_name); imgStrs.push_back(path); } if(dir) closedir(dir); }
AutocompleteQuery ParseMentionHashtagBotCommandQuery( not_null<const Ui::InputField*> field) { auto result = AutocompleteQuery(); const auto cursor = field->textCursor(); if (cursor.hasSelection()) { return result; } const auto position = cursor.position(); const auto document = field->document(); const auto block = document->findBlock(position); for (auto item = block.begin(); !item.atEnd(); ++item) { const auto fragment = item.fragment(); if (!fragment.isValid()) { continue; } const auto fragmentPosition = fragment.position(); const auto fragmentEnd = fragmentPosition + fragment.length(); if (fragmentPosition >= position || fragmentEnd < position) { continue; } const auto format = fragment.charFormat(); if (format.isImageFormat()) { continue; } bool mentionInCommand = false; const auto text = fragment.text(); for (auto i = position - fragmentPosition; i != 0; --i) { if (text[i - 1] == '@') { if ((position - fragmentPosition - i < 1 || text[i].isLetter()) && (i < 2 || !(text[i - 2].isLetterOrNumber() || text[i - 2] == '_'))) { result.fromStart = (i == 1) && (fragmentPosition == 0); result.query = text.mid(i - 1, position - fragmentPosition - i + 1); } else if ((position - fragmentPosition - i < 1 || text[i].isLetter()) && i > 2 && (text[i - 2].isLetterOrNumber() || text[i - 2] == '_') && !mentionInCommand) { mentionInCommand = true; --i; continue; } return result; } else if (text[i - 1] == '#') { if (i < 2 || !(text[i - 2].isLetterOrNumber() || text[i - 2] == '_')) { result.fromStart = (i == 1) && (fragmentPosition == 0); result.query = text.mid(i - 1, position - fragmentPosition - i + 1); } return result; } else if (text[i - 1] == '/') { if (i < 2) { result.fromStart = (i == 1) && (fragmentPosition == 0); result.query = text.mid(i - 1, position - fragmentPosition - i + 1); } return result; } if (position - fragmentPosition - i > 127 || (!mentionInCommand && (position - fragmentPosition - i > 63))) { break; } if (!text[i - 1].isLetterOrNumber() && text[i - 1] != '_') { break; } } break; } return result; }