本文整理汇总了C++中AString::Valid方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::Valid方法的具体用法?C++ AString::Valid怎么用?C++ AString::Valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::Valid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InsertPattern
bool ADVBPatterns::InsertPattern(const AString& user, const AString& pattern)
{
const ADVBConfig& config = ADVBConfig::Get();
ADVBLock lock("patterns");
bool changed = false;
if (user.Valid()) changed = AddPatternToFile(config.GetUserPatternsPattern().SearchAndReplace("{#?}", user), pattern);
else changed = AddPatternToFile(config.GetPatternsFile(), pattern);
return changed;
}
示例2: UpdatePatternInFile
bool ADVBPatterns::UpdatePatternInFile(const AString& filename, const AString& pattern, const AString& newpattern)
{
const ADVBConfig& config = ADVBConfig::Get();
AString filename1 = filename + ".new";
AStdFile ifp, ofp;
bool changed = false, found = false;
if (ifp.open(filename)) {
if (ofp.open(filename1, "w")) {
AString line;
while (line.ReadLn(ifp) >= 0) {
if (line == pattern) {
if (newpattern.Valid()) ofp.printf("%s\n", newpattern.str());
changed = found = true;
if (newpattern.Valid()) {
config.logit("Changed pattern '%s' to '%s' in file '%s'", pattern.str(), newpattern.str(), filename.str());
}
else {
config.logit("Deleted pattern '%s' from file '%s'", pattern.str(), filename.str());
}
}
else if (line.Words(0).Valid()) ofp.printf("%s\n", line.str());
else changed = true;
}
ofp.close();
}
ifp.close();
if (changed) {
remove(filename);
rename(filename1, filename);
}
else remove(filename1);
}
return found;
}
示例3: ReadJPEGInfo
bool ReadJPEGInfo(const char *filename, JPEG_INFO& info)
{
EXIFINFO exinfo;
Exif exif(&exinfo);
FILE *fp;
bool success = false;
memset(&exinfo, 0, sizeof(exinfo));
if ((fp = fopen(filename, "rb")) != NULL) {
if (exif.DecodeExif(fp)) {
info.CameraMake = exinfo.CameraMake;
info.CameraModel = exinfo.CameraModel;
info.Width = exinfo.Width;
info.Height = exinfo.Height;
info.Orientation = exinfo.Orientation;
info.bDateValid = false;
info.Comments = exinfo.Comments;
AString str = exinfo.DateTime;
if (str.Valid()) {
//printf("File '%s' has date '%s'\n", filename, str.str());
str.Replace(":/-.", " ");
ADateTime& dt = info.DateTime;
uint_t word = 0;
uint16_t year = str.Word(word++);
uint8_t month = str.Word(word++);
uint8_t day = str.Word(word++);
uint8_t hour = str.Word(word++);
uint8_t minute = str.Word(word++);
uint8_t second = str.Word(word++);
if ((year >= 1980) && RANGE(month, 1, 12) && RANGE(day, 1, 31) && (hour <= 23) && (minute <= 59) && (second <= 61)) {
dt.Set(day, month, year, hour, minute, second);
info.bDateValid = true;
}
}
success = true;
}
fclose(fp);
}
return success;
}
示例4: UpdatePattern
bool ADVBPatterns::UpdatePattern(const AString& olduser, const AString& oldpattern, const AString& newuser, const AString& newpattern)
{
ADVBLock lock("patterns");
bool changed = false;
if (newuser != olduser) {
changed |= DeletePattern(olduser, oldpattern);
if (newpattern.Valid()) {
changed |= InsertPattern(newuser, newpattern);
}
}
else if (newpattern != oldpattern) changed |= UpdatePattern(newuser, oldpattern, newpattern);
return changed;
}
示例5: CreateDirectory
bool CreateDirectory(const AString& dir)
{
AString parentdir = dir.PathPart();
FILE_INFO file;
bool success = true;
if (parentdir.Valid() && (parentdir != "/") && !::GetFileInfo(parentdir, &file)) success = CreateDirectory(parentdir);
if (success && (dir.FilePart().Valid()) && !::GetFileInfo(dir, &file)) {
#ifdef __LINUX__
success = (mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH) == 0);
#else
success = ::CreateDirectoryA(dir.str(), NULL);
#endif
}
return success;
}
示例6: Recurse
bool Recurse(const AString& Path, const AString& Pattern, uint_t nSubDirs, bool (*fn)(const FILE_INFO *file, void *Context), void *Context)
{
AString pattern = ParsePathRegex(Pattern);
FILE_INFO file;
DIR *handle;
bool ok = true, any = IsRegexAnyPattern(pattern);
if ((handle = opendir(Path.Valid() ? Path : ".")) != NULL) {
struct dirent *ent;
while (ok && ((ent = readdir(handle)) != NULL)) {
if (SetFileData(Path, *ent, &file)) {
if ((file.ShortName != ".") && (file.ShortName != "..")) {
bool done = false;
if (any || MatchPathRegex(file.ShortName, pattern)) {
ok = (*fn)(&file, Context);
if (!ok) break;
done = true;
}
if ((nSubDirs > 0) && (file.Attrib & FILE_FLAG_IS_DIR)) {
if (!done) {
ok = (*fn)(&file, Context);
if (!ok) break;
}
ok = Recurse(file.FileName, Pattern, nSubDirs - 1, fn, Context);
if (!ok) break;
}
}
}
}
closedir(handle);
}
return ok;
}
示例7: ParsePattern
bool ADVBPatterns::ParsePattern(ADataList& patternlist, const AString& line, AString& errors, const AString& user)
{
//const ADVBConfig& config = ADVBConfig::Get();
PATTERN *pattern;
bool success = false;
patternlist.SetDestructor(&__DeletePattern);
if ((pattern = new PATTERN) != NULL) {
AString errs = ParsePattern(line, *pattern, user);
if (errs.Valid()) {
//config.printf("Error parsing '%s': %s", line.str(), errs.str());
errors += errs + "\n";
}
if ((pattern->list.Count() > 0) || pattern->errors.Valid()) {
patternlist.Add((uptr_t)pattern);
success = true;
}
}
return success;
}
示例8: ListUsers
void ADVBConfig::ListUsers(AList& list) const
{
AHash users(10);
AList userpatterns;
AString filepattern = GetUserPatternsPattern();
AString filepattern_parsed = ParseRegex(filepattern);
AString _users = GetConfigItem("users");
AStdFile fp;
uint_t i, n = _users.CountColumns();
//debug("Reading users from config %s\n", config.GetFilename().str());
for (i = 0; i < n; i++) {
AString user = _users.Column(i).Words(0);
if (!users.Exists(user)) {
users.Insert(user, 0);
list.Add(new AString(user));
}
}
if (fp.open(GetPatternsFile())) {
AString line;
while (line.ReadLn(fp) >= 0) {
AString user;
int p;
if ((p = line.PosNoCase(" user:=")) >= 0) user = line.Mid(p + 7).Word(0).DeQuotify();
else if (line.PosNoCase("user:=") == 0) user = line.Mid(6).Word(0).DeQuotify();
if (user.Valid() && !users.Exists(user)) {
users.Insert(user, 0);
list.Add(new AString(user));
}
}
fp.close();
}
::CollectFiles(filepattern.PathPart(), filepattern.FilePart(), 0, userpatterns);
const AString *file = AString::Cast(userpatterns.First());
while (file) {
AString user;
ADataList regions;
if (MatchRegex(*file, filepattern_parsed, regions)) {
const REGEXREGION *region = (const REGEXREGION *)regions[0];
if (region) {
user = file->Mid(region->pos, region->len);
if (!users.Exists(user)) {
users.Insert(user, 0);
list.Add(new AString(user));
}
}
}
file = file->Next();
}
list.Sort(&AString::AlphaCompareCase);
}