uael / sv

libsv - Public domain cross-platform semantic versioning in c99

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a better way to find a valid semantic version string in the text?

waruqi opened this issue · comments

commented

Currently I use lua pattern matching to find valid semantic versions, but I don't feel very reliable.

 function semver.match(str, pos, pattern) 
     local patterns = pattern or {"%d+[.]%d+[-+.%w]*", "%d+[.]%d+[.]%d+", "%d+[.]%d+"} 
     for _, pattern in ipairs(table.wrap(patterns)) do 
         local version_str = str:match(pattern, pos) 
         if version_str then 
             local info = semver.parse(version_str) 
             if info then 
                 local instance = table.inherit(_instance) 
                 instance._INFO = info 
                 return instance 
             end 
         end 

Would it be better to provide a semver.match interface in the sv library for fast matching?

see xmake-io/xmake#677