所以我刚刚意识到,如果找到的第一个字符串不正确,我使用的当前过滤器似乎只能正常工作。
Module m = current
Object o = current
Filter f
load view "Standard view"
//column attribute Object Type
insert(column 3)
attribute(column 3, "Object Type")
width(column 3, 100)
f1 = attribute "Object Type" == "Requirement"
f2 = attribute "Object Type" == "Derived Requirement"
f3 = contains(attribute "Object Text", "(Testing) ", true)
for o in m do
{
f = (f1 || f2) && !(f3)
}
set f
filtering on
refresh current
示例:这将是我当前的表格(不擅长制作表格)
ID| Module Information |Object Type
__|______________________________________|____________________
1 | (Teting) this is the incorrect format| Requirements
__|______________________________________|____________________
2 | (Testing) this is also correct format| Derived Requirements
| (Test) this is incorrect format |
__|______________________________________|____________________
3 | (Testing) this is the correct format | Requirements
| (Testing) this is the correct format |
__|______________________________________|____________________
4 | (Testing) this is the correct format | Requirements
| (Teting) this is incorrect format |
__|______________________________________|____________________
所以,如果我在这里运行我的脚本,那只会告诉我
ID| Module Information |Object Type
__|______________________________________|____________________
1 | (Teting) this is the incorrect format| Requirements
而不是我希望它会告诉我:
ID| Module Information |Object Type
__|______________________________________|____________________
1 | (Teting) this is the incorrect format| Requirements
__|______________________________________|____________________
2 | (Testing) this is also correct format| Derived Requirements
| (Test) this is incorrect format |
__|______________________________________|____________________
4 | (Testing) this is the correct format | Requirements
| (Teting) this is incorrect format |
__|______________________________________|____________________
那么我将如何展示正确的视图呢?我认为它与循环有关 “对象文本包含”过滤器,但我不确定如何做到这一点。
答案 0 :(得分:0)
据我所知,您的DXL工作正常。但是,您可能想稍微改变一下您的问题。
首先,您的DXL正在检查Object Type
是否是"要求"或者"派生要求",而您的测试数据有"要求 s "和"派生要求 s "。
其次,您的代码f = (f1 || f2) && !(f3)
正在检查对象类型是Requirement
还是Derived Requirement
,而不包含"(Testing)"
对象文本中的任何地方。您的代码执行此操作,因此不会提供您期望的结果,因为最后三个对象包含文本"(Testing)"
。
我认为您所追求的是检查并非所有行包含"(Testing)"
,而不是无。在这种情况下,代码将类似于:
Module m = current
Object o = current
Regexp REGEX_INVALID = regexp2("\\(Testing\\)")
Regexp REGEX_VALID = regexp2("\\(.*\\)")
Buffer searchText = create
Buffer original = create
//Returns true if Object Text contains any one or more pairs of brackets that do not match (Testing)
bool filterObjectText(string objText)
{
searchText = objText
original = objText
while(REGEX_VALID searchText)
{
if (REGEX_INVALID searchText)
{
int offset = null
int subStrLength = null
findPlainText(tempStringOf(searchText), "(Testing)", offset, subStrLength, true)
searchText = searchText[offset + subStrLength:]
}
else
{
return true
}
}
return false
}
filtering off
for o in m do
{
string objectType = o."Object Type"
string objectText = o."Object Text"
if ((objectType == "Requirements" || objectType == "Derived Requirements") && filterObjectText(objectText))
{
accept o
}
else
{
reject o
}
}
filtering on
refresh current