2016-10-25 210 views
1

所以我才意識到,我一直在使用當前的過濾器似乎只在發現第一個字符串是不正確的正常工作,應用過濾器。DXL門需要幫助使用循環

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是「規定」或「派生需求」,而您的測試數據有「要求小號」和「派生需求小號」。

其次你的代碼f = (f1 || f2) && !(f3)被檢查對象類型爲RequirementDerived 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