當前位置: 首頁>>代碼示例>>Python>>正文


Python QgsStringReplacement.process方法代碼示例

本文整理匯總了Python中qgis.core.QgsStringReplacement.process方法的典型用法代碼示例。如果您正苦於以下問題:Python QgsStringReplacement.process方法的具體用法?Python QgsStringReplacement.process怎麽用?Python QgsStringReplacement.process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在qgis.core.QgsStringReplacement的用法示例。


在下文中一共展示了QgsStringReplacement.process方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testReplace

# 需要導入模塊: from qgis.core import QgsStringReplacement [as 別名]
# 或者: from qgis.core.QgsStringReplacement import process [as 別名]
    def testReplace(self):
        """ test applying replacements"""

        # case insensitive
        r = QgsStringReplacement('match', 'replace', False, False)
        self.assertEqual(r.process('one MaTch only'), 'one replace only')
        self.assertEqual(r.process('more then one MaTch here match two'), 'more then one replace here replace two')
        self.assertEqual(r.process('match start and end MaTch'), 'replace start and end replace')
        self.assertEqual(r.process('no hits'), 'no hits')
        self.assertEqual(r.process('some exmatches here'), 'some exreplacees here')
        self.assertEqual(r.process(''), '')

        # case sensitive
        r = QgsStringReplacement('match', 'replace', True, False)
        self.assertEqual(r.process('one MaTch only'), 'one MaTch only')
        self.assertEqual(r.process('one match only'), 'one replace only')

        # whole word only, case insensitive
        r = QgsStringReplacement('match', 'replace', False, True)
        self.assertEqual(r.process('some exmatches here'), 'some exmatches here')
        self.assertEqual(r.process('some match here'), 'some replace here')
        self.assertEqual(r.process('some exmatches MaTch here'), 'some exmatches replace here')
        self.assertEqual(r.process('some match maTCh here'), 'some replace replace here')
        self.assertEqual(r.process('some -match. here'), 'some -replace. here')
        self.assertEqual(r.process('match here'), 'replace here')
        self.assertEqual(r.process('some match'), 'some replace')

        # whole word only, case sensitive
        r = QgsStringReplacement('match', 'replace', True, True)
        self.assertEqual(r.process('some exmatches here'), 'some exmatches here')
        self.assertEqual(r.process('some match here'), 'some replace here')
        self.assertEqual(r.process('some exmatches MaTch here'), 'some exmatches MaTch here')
        self.assertEqual(r.process('some match maTCh here'), 'some replace maTCh here')
開發者ID:,項目名稱:,代碼行數:35,代碼來源:


注:本文中的qgis.core.QgsStringReplacement.process方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。