本文整理汇总了C++中AString::Mid方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::Mid方法的具体用法?C++ AString::Mid怎么用?C++ AString::Mid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::Mid方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReplaceTerms
AString ADVBConfig::ReplaceTerms(const AString& user, const AString& subitem, const AString& _str) const
{
AString str = _str;
int p1, p2;
while (((p1 = str.Pos("{conf:")) >= 0) && ((p2 = str.Pos("}", p1)) >= 0)) {
AString item = GetUserSubItemConfigItem(user, subitem, str.Mid(p1 + 6, p2 - p1 - 6));
str = str.Left(p1) + item + str.Mid(p2 + 1);
}
return str;
}
示例2: ReadReplacementsFile
bool ADVBConfig::ReadReplacementsFile(std::vector<REPLACEMENT>& replacements, const AString& filename) const
{
AStdFile fp;
bool success = false;
if (fp.open(filename)) {
AString line;
//printf("Reading replacements file '%s':", filename.str());
while (line.ReadLn(fp) >= 0) {
int p = 0;
if ((line.Word(0)[0] != ';') && ((p = line.Pos("=")) >= 0)) {
REPLACEMENT repl = {
line.Left(p).Word(0).DeQuotify(),
line.Mid(p + 1).Word(0).DeQuotify(),
};
//printf("Replacement: '%s' -> '%s'", repl.search.str(), repl.replace.str());
replacements.push_back(repl);
}
}
fp.close();
success = true;
}
else logit("Failed to open replacements file '%s'", filename.str());
return success;
}
示例3: GetRelativePath
AString ADVBConfig::GetRelativePath(const AString& filename) const
{
AString res;
if (filename.StartsWith(GetRecordingsDir())) res = AString("/videos").CatPath(filename.Mid(GetRecordingsDir().len()));
return res;
}
示例4: EnablePattern
bool ADVBPatterns::EnablePattern(const AString& user, const AString& pattern)
{
ADVBLock lock("patterns");
bool changed = false;
if (pattern[0] == '#') {
changed = UpdatePattern(user, pattern, pattern.Mid(1));
}
return changed;
}
示例5: ConvertSimpleType
/*--------------------------------------------------------------------------------*/
AString PostgresDatabase::ConvertSimpleType(const AString& ctype) const
{
AString type;
if (ctype == "id") type = "integer not null primary key"; // primary key id
else if (ctype == "id64") type = "bigint not null primary key"; // primary key id (64-bit)
else if (ctype.Left(6) == "string") type.printf("varchar%s", ctype.Mid(6).SearchAndReplace("[", "(").SearchAndReplace("]", ")").str()); // string type / varchar
else if (ctype == "datetime") type = "timestamp";
else if (ctype == "float") type = "real";
else if (ctype == "double") type = "real";
else if (ctype == "short") type = "smallint";
else if (ctype == "int64") type = "bigint";
else if (ctype == "") type = "integer";
return type;
}
示例6: AddItem
static bool AddItem(const CXmlItem &item, CObjectVector<CFile> &files, int parent)
{
if (!item.IsTag)
return true;
if (item.Name == "file")
{
CFile file;
file.Parent = parent;
parent = files.Size();
file.Name = item.GetSubStringForTag("name");
AString type = item.GetSubStringForTag("type");
if (type == "directory")
file.IsDir = true;
else if (type == "file")
file.IsDir = false;
else
return false;
int dataIndex = item.FindSubTag("data");
if (dataIndex >= 0 && !file.IsDir)
{
file.HasData = true;
const CXmlItem &dataItem = item.SubItems[dataIndex];
if (!ParseUInt64(dataItem, "size", file.Size))
return false;
if (!ParseUInt64(dataItem, "length", file.PackSize))
return false;
if (!ParseUInt64(dataItem, "offset", file.Offset))
return false;
file.Sha1IsDefined = ParseSha1(dataItem, "extracted-checksum", file.Sha1);
// file.packSha1IsDefined = ParseSha1(dataItem, "archived-checksum", file.packSha1);
int encodingIndex = dataItem.FindSubTag("encoding");
if (encodingIndex >= 0)
{
const CXmlItem &encodingItem = dataItem.SubItems[encodingIndex];
if (encodingItem.IsTag)
{
AString s = encodingItem.GetPropertyValue("style");
if (s.Length() >= 0)
{
AString appl = "application/";
if (s.Left(appl.Length()) == appl)
{
s = s.Mid(appl.Length());
AString xx = "x-";
if (s.Left(xx.Length()) == xx)
{
s = s.Mid(xx.Length());
if (s == "gzip")
s = METHOD_NAME_ZLIB;
}
}
file.Method = s;
}
}
}
}
file.CTime = ParseTime(item, "ctime");
file.MTime = ParseTime(item, "mtime");
file.ATime = ParseTime(item, "atime");
files.Add(file);
}
for (int i = 0; i < item.SubItems.Size(); i++)
if (!AddItem(item.SubItems[i], files, parent))
return false;
return true;
}
示例7: 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);
}
示例8: Configure
void MotionDetector::Configure()
{
AString nstr = AString("%").Arg(index);
log.printf("%s[%u]: Reading new settings...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index);
stream.Close();
stream.SetUsernameAndPassword(GetSetting("username", "admin"),
GetSetting("password", "arsebark"));
AString camera = GetSetting("camera", "");
log.printf("%s[%u]: Connecting to %s...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index, camera.str());
if (!stream.OpenHost(camera)) {
log.printf("%s[%u]: Failed to connect to %s...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index, camera.str());
}
imagedir = GetSetting("imagedir", "/media/cctv");
imagefmt = GetSetting("filename", "%Y-%M-%D/%h/Image-{camera}-%Y-%M-%D-%h-%m-%s-%S");
detimgdir = GetSetting("detimagedir");
detimgfmt = GetSetting("detfilename", "%Y-%M-%D/%h/detection/Image-{camera}-%Y-%M-%D-%h-%m-%s-%S");
detcmd = GetSetting("detcommand", "");
nodetcmd = GetSetting("nodetcommand", "");
coeff = (double)GetSetting("coeff", "1.0e-3");
avgfactor = (double)GetSetting("avgfactor", "1.0");
sdfactor = (double)GetSetting("sdfactor", "2.0");
redscale = (double)GetSetting("rscale", "1.0");
grnscale = (double)GetSetting("gscale", "1.0");
bluscale = (double)GetSetting("bscale", "1.0");
threshold = (double)GetSetting("threshold", "3000.0");
verbose = (uint_t)GetSetting("verbose", "0");
matmul = 1.f;
matwid = mathgt = 0;
AString _matrix = GetSetting("matrix", "");
if (_matrix.Valid()) {
uint_t row, nrows = _matrix.CountLines(";");
uint_t col, ncols = 1;
int p;
if ((p = _matrix.Pos("*")) >= 0) {
AString mul = _matrix.Mid(p + 1);
_matrix = _matrix.Left(p);
if ((p = mul.Pos("/")) >= 0) {
matmul = (float)mul.Left(p) / (float)mul.Mid(p + 1);
}
else matmul = (float)mul;
}
else if ((p = _matrix.Pos("/")) >= 0) {
AString mul = _matrix.Mid(p + 1);
_matrix = _matrix.Left(p);
matmul = 1.f / (float)mul;
}
for (row = 0; row < nrows; row++) {
uint_t n = _matrix.Line(row, ";").CountLines(",");
ncols = MAX(ncols, n);
}
nrows |= 1;
ncols |= 1;
matrix.resize(nrows * ncols);
for (row = 0; row < nrows; row++) {
AString line = _matrix.Line(row,";");
for (col = 0; col < ncols; col++) matrix[col + row * ncols] = (float)line.Line(col, ",");
}
matwid = ncols;
mathgt = nrows;
#if 0
printf("Matrix is %u x %u:\n", matwid, mathgt);
for (row = 0; row < nrows; row++) {
for (col = 0; col < ncols; col++) printf("%8.3f", matrix[col + row * ncols]);
printf("\n");
}
printf("Multiplier %0.6f\n", matmul);
#endif
}
else matrix.resize(0);
}
示例9: DecodeXML
bool DecodeXML(AStructuredNode& root, const AString& str)
{
AStructuredNode *pNode = &root;
AKeyValuePair *pAttr;
ADataList stack;
uint_t p1 = 0, p2;
while (IsXMLWhiteSpace(str[p1])) p1++;
while (!HasQuit() && pNode && (str[p1] == '<')) {
bool popnode = false;
p1++;
if (str[p1] == '/') {
p1++;
if ((pNode != &root) && ((p2 = FindXMLMarker(str, p1)) > p1)) {
uint_t p3 = p1;
if (IsSymbolStart(str[p1])) p1++;
while (IsXMLNameChar(str[p1])) p1++;
AString name = str.Mid(p3, p1 - p3);
if (name == pNode->Key) {
if (debug_decode) debug("Closing node '%s'\n", pNode->Key.str());
popnode = true;
p1 = p2 + 1;
}
else {
debug("Unknown close object '%s' at %u\n", name.str(), p1);
break;
}
}
else {
debug("Unknown close marker at %u\n", p1);
break;
}
}
else if (str.Mid(p1, 3) == "!--") {
if ((p2 = str.Pos("-->", p1 + 3)) > p1) p1 = p2 + 2;
else {
debug("Unterminated comment marker at %u\n", p1);
break;
}
}
else if ((p2 = FindXMLMarker(str, p1)) > p1) {
if (pNode) stack.Push((void *)pNode);
if ((pNode = new AStructuredNode) != NULL) {
uint_t p3 = p2;
bool complete = ((str[p3 - 1] == '/') || ((str[p1] == '?') && (str[p3 - 1] == '?')));
if (complete) p3--;
complete |= (str[p1] == '!');
if ((str[p1] == '?') || (str[p1] == '!')) pNode->SetType(str[p1++]);
while (IsXMLWhiteSpace(str[p1])) p1++;
uint_t p4 = p1;
if (IsSymbolStart(str[p1])) p1++;
while (IsXMLNameChar(str[p1])) p1++;
pNode->Key = str.Mid(p4, p1 - p4).DeHTMLify();
if (debug_decode) debug("Created new node '%s' (%s)\n", pNode->Key.str(), complete ? "complete" : "open");
while (IsXMLWhiteSpace(str[p1])) p1++;
while (p1 < p3) {
p4 = p1;
if (IsSymbolStart(str[p1])) p1++;
while (IsXMLNameChar(str[p1])) p1++;
uint_t p5 = p1;
while (IsXMLWhiteSpace(str[p1])) p1++;
if (str[p1] == '=') p1++;
while (IsXMLWhiteSpace(str[p1])) p1++;
int quote = 0;
if (IsQuoteChar(str[p1])) quote = str[p1++];
uint_t p6 = p1;
while (str[p1] && ((quote && (str[p1] != quote)) ||
(!quote && !IsXMLWhiteSpace(str[p1])))) p1++;
uint_t p7 = p1;
if (quote && (str[p1] == quote)) p1++;
while (IsXMLWhiteSpace(str[p1])) p1++;
if ((p5 > p4) && ((pAttr = new AKeyValuePair) != NULL)) {
pAttr->Key = str.Mid(p4, p5 - p4).DeHTMLify();
pAttr->Value = str.Mid(p6, p7 - p6).DeHTMLify();
pNode->AddAttribute(pAttr);
if (debug_decode) debug("Added attribute '%s'='%s' to '%s'\n", pAttr->Key.str(), pAttr->Value.str(), pNode->Key.str());
}
else break;
}
AStructuredNode *pParent = (AStructuredNode *)stack.Last();
if (pParent) pParent->AddChild(pNode);
//.........这里部分代码省略.........
示例10: ParsePattern
AString ADVBPatterns::ParsePattern(const AString& _line, PATTERN& pattern, const AString& user)
{
const ADVBConfig& config = ADVBConfig::Get();
ADataList& list = pattern.list;
AString& errors = pattern.errors;
AString line = config.ReplaceTerms(user, _line);
TERM *term;
uint_t i;
pattern.exclude = false;
pattern.enabled = true;
pattern.scorebased = false;
pattern.pri = 0;
pattern.user = user;
pattern.pattern = line;
if (pattern.user.Valid()) {
pattern.pri = (int)config.GetUserConfigItem(pattern.user, "pri");
}
list.DeleteList();
list.SetDestructor(&__DeleteTerm);
i = 0;
while (IsWhiteSpace(line[i])) i++;
if (line[i] == '#') {
pattern.enabled = false;
i++;
}
else if (line[i] == ';') {
return errors;
}
while (IsWhiteSpace(line[i])) i++;
if (line[i]) {
while (line[i] && errors.Empty()) {
if (!IsSymbolStart(line[i])) {
errors.printf("Character '%c' (at %u) is not a legal field start character (term %u)", line[i], i, list.Count() + 1);
break;
}
uint_t fieldstart = i++;
while (IsSymbolChar(line[i])) i++;
AString field = line.Mid(fieldstart, i - fieldstart).ToLower();
while (IsWhiteSpace(line[i])) i++;
if (field == "exclude") {
pattern.exclude = true;
continue;
}
const FIELD *fieldptr = (const FIELD *)ADVBProg::fieldhash.Read(field);
if (!fieldptr) {
uint_t nfields;
const FIELD *fields = ADVBProg::GetFields(nfields);
errors.printf("'%s' (at %u) is not a valid search field (term %u), valid search fields are: ", field.str(), fieldstart, list.Count() + 1);
for (i = 0; i < nfields; i++) {
const FIELD& field = fields[i];
if (i) errors.printf(", ");
errors.printf("'%s'", field.name);
}
break;
}
uint_t opstart = i;
const char *str = line.str() + i;
bool isassign = fieldptr->assignable;
uint_t j;
uint_t opindex = 0, opcode = Operator_EQ;
for (j = 0; j < NUMBEROF(operators); j++) {
if (((isassign == operators[j].assign) ||
(isassign && !operators[j].assign)) &&
(operators[j].fieldtypes & (1U << fieldptr->type)) &&
(strncmp(str, operators[j].str, operators[j].len) == 0)) {
i += operators[j].len;
opindex = j;
opcode = operators[j].opcode;
break;
}
}
while (IsWhiteSpace(line[i])) i++;
AString value;
bool implicitvalue = false;
if (j == NUMBEROF(operators)) {
if (!line[i] || IsSymbolStart(line[i])) {
if (fieldptr->assignable) {
switch (fieldptr->type) {
case FieldType_string:
break;
case FieldType_date:
value = "now";
break;
//.........这里部分代码省略.........