Jamoma API  0.6.0.a19
TTNodeLib.cpp
1 /*
2  * Jamoma file to declare the NodeLib
3  * Copyright © 2011, Théo de la Hogue
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTNodeLib.h"
10 #include "TTRegex.h"
11 
12 void TTNodeLibInit()
13 {
14 #ifndef DISABLE_NODELIB
15 
16  // Global regex for TTAddress parsing
17  ttRegexForDirectory = new TTRegex(R"(([-\w]+):/)");
18  ttRegexForAttribute = new TTRegex(":+", 0);
19  ttRegexForParent = new TTRegex(R"((.*)/+(\S+))");
20  ttRegexForInstance = new TTRegex("[.]", 0);
21  ttRegexForInstanceZero = new TTRegex(R"(\.0)", 0);
22 
23 #endif
24 }
25 
26 TTErr convertUpperCasedNameInAddress(TTSymbol upperCasedName, TTAddress& convertedInAddress)
27 {
28  TTUInt32 upperCasedNameSize = strlen(upperCasedName.c_str());
29  TTCString upperCasedNameCString = new char[upperCasedNameSize+1];
30  TTUInt32 nbUpperCase = 0;
31  TTUInt32 i;
32  TTCString convertedNameCString = NULL;
33  TTUInt32 convertedNameSize = 0;
34 
35  strncpy(upperCasedNameCString, upperCasedName.c_str(), upperCasedNameSize+1);
36 
37  // "ExampleName" to "example/name"
38  // "anyOtherExample" to "any/other/example"
39  if ((upperCasedNameCString[0] > 64 && upperCasedNameCString[0] < 91) || (upperCasedNameCString[0] > 96 && upperCasedNameCString[0] < 123)) {
40 
41  // count how many upper-case letter there are in the TTName after the first letter
42  for (i=1; i<upperCasedNameSize; i++) {
43  if (upperCasedNameCString[i] > 64 && upperCasedNameCString[i] < 91)
44  nbUpperCase++;
45  }
46 
47  // prepare the convertedName
48  convertedNameSize = upperCasedNameSize + nbUpperCase;
49  convertedNameCString = new char[convertedNameSize+1];
50 
51  // convert first letter to lower-case if needed
52  if (upperCasedNameCString[0] > 64 && upperCasedNameCString[0] < 91)
53  convertedNameCString[0] = upperCasedNameCString[0] + 32;
54  else
55  convertedNameCString[0] = upperCasedNameCString[0];
56 
57  // copy each letter while checking upper-case letter to replace them by a / + lower-case letter
58  nbUpperCase = 0;
59  for (i=1; i<upperCasedNameSize; i++) {
60  if (upperCasedNameCString[i] > 64 && upperCasedNameCString[i] < 91) {
61  convertedNameCString[i + nbUpperCase] = '/';
62  convertedNameCString[i + nbUpperCase + 1] = upperCasedNameCString[i] + 32;
63  nbUpperCase++;
64  }
65  else
66  convertedNameCString[i + nbUpperCase] = upperCasedNameCString[i];
67  }
68 
69  // ends the CString with a NULL letter
70  convertedNameCString[convertedNameSize] = 0;
71 
72  convertedInAddress = TTAddress(convertedNameCString);
73 
74  delete convertedNameCString;
75  convertedNameCString = NULL;
76  }
77  else
78  convertedInAddress = TTAddress(upperCasedName);
79 
80  delete upperCasedNameCString;
81  upperCasedNameCString = NULL;
82 
83  return kTTErrNone;
84 }
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Definition: TTAddress.h:29
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
No Error.
Definition: TTBase.h:343