【问题标题】:Constructing a location from a string从字符串构造位置
【发布时间】:2019-05-13 11:53:54
【问题描述】:

我的网络服务器收到以下字符串:"|project://Detector/src/exporter.rsc|(1762,28,<45,10>,<45,38>)" 使用 toLocation() 函数将其转换为位置将导致 MalFormedURI 错误。

我可以使用toLocation() 函数将字符串loc myLoc = toLocation("project://Detector/src/exporter.rsc"); 转换为一个位置。 使用正则表达式,我可以提取"0,10,<2,0>,<4,10>"。 但现在问题是我可以做到:myLoc(0,10,<2,0>,<4,10>),但我不能做到myLoc("0,10,<2,0>,<4,10>")。我可以使用正则表达式提取所有这些位置数据,然后将其添加到该位置,但这会导致讨厌的代码。

使用位置数据转换字符串的最佳做法是什么,例如。 "|project://Detector/src/exporter.rsc|(1762,28,<45,10>,<45,38>)" 到包含位置数据的位置。

【问题讨论】:

    标签: rascal


    【解决方案1】:

    我认为最稳健的方式是这样的:

    import ValueIO;
    str theString = "|project://Detector/src/exporter.rsc|(1762,28,\<45,10\>,\<45,38\>)";
    theLoc = readTextValueString(#loc, theString);
    

    该函数可能会引发您可以捕获和处理的解析错误,但我猜您的设置不会发生这种情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      • 1970-01-01
      • 2015-06-28
      • 2020-07-26
      相关资源
      最近更新 更多