diff OrthancServer/Sources/ServerToolbox.cpp @ 5244:72dfa0ac84eb db-protobuf

lookup for labels in orthanc explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 06 Apr 2023 16:55:55 +0200
parents feba2b0e91bc
children eb2684260c19
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerToolbox.cpp	Thu Apr 06 16:04:23 2023 +0200
+++ b/OrthancServer/Sources/ServerToolbox.cpp	Thu Apr 06 16:55:55 2023 +0200
@@ -287,5 +287,40 @@
         }
       }
     }
+
+    
+    bool IsValidLabel(const std::string& label)
+    {
+      if (label.empty())
+      {
+        return false;
+      }
+      
+      for (size_t i = 0; i < label.size(); i++)
+      {
+        if (!(label[i] == '.' ||
+              label[i] == '_' ||
+              label[i] == '-' ||
+              (label[i] >= 'a' && label[i] <= 'z') ||
+              (label[i] >= 'A' && label[i] <= 'Z') ||
+              (label[i] >= '0' && label[i] <= '9')))
+        {
+          return false;
+        }
+      }
+
+      return true;
+    }
+
+
+    void CheckValidLabel(const std::string& label)
+    {
+      if (!IsValidLabel(label))
+      {
+        throw OrthancException(ErrorCode_ParameterOutOfRange,
+                               "A label must be a non-empty, alphanumeric string, "
+                               "possibly with '.', '_', or '-' characters, but got: " + label);
+      }
+    }
   }
 }