]> git.ardis.lu - simulate-etherscan-function-display/commitdiff
Update regex to match valid identifier chars
authorArdis Lu <ardisglu@gmail.com>
Sat, 8 Jul 2023 06:02:11 +0000 (23:02 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sat, 8 Jul 2023 06:02:11 +0000 (23:02 -0700)
Reference: https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityLexer.Identifier

index.html

index fd21a3633dd8eea92d6d8c369f959aaec0258e51..0eaa6bbd939fcdb0b8f0c47d82f56aaf86034bac 100644 (file)
   <script type="module">
     // Extract all function names from arbitrary Solidity code
     function getFunctions(code) {
-      const re = /^(function )?(?<name>[\w]+)\(.*?\)/;
+      const re = /^(function )?(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\(.*?\)/;
       const functions = [];
       for (let line of code.split('\n')) {
         line = line.trim();
     // Converts a camelCase string into Title Case With Spaces for human readability.
     function camelCaseToTitleCase(str) {
       str = str[0].toLocaleUpperCase() + str.slice(1);
-      return str.replaceAll(/([A-Z]+)/g, ' $1').slice(1);
+      return str.replaceAll(/([A-Z$_]+)/g, ' $1').slice(1);
     }
 
     function debounce(fn, wait) {
This page took 0.04299 seconds and 4 git commands to generate.