Initial update of comments to JSDoc format.
diff --git a/js/Name.js b/js/Name.js
index 605f110..cda44bb 100644
--- a/js/Name.js
+++ b/js/Name.js
@@ -4,30 +4,29 @@
* This class represents a Name as an array of components where each is a byte array.
*/
-/*
- * Create a new Name from _components.
- * If _components is a string, parse it as a URI.
- * If _components is a Name, add a deep copy of its components.
- * Otherwise it is an array of components where each is a string, byte array, ArrayBuffer, Uint8Array
- * or Name.
- * Convert and store as an array of Uint8Array.
- * If a component is a string, encode as utf8.
+/**
+ * Create a new Name from components.
+ *
+ * @constructor
+ * @param {String|Name|Array<String|Array<number>|ArrayBuffer|Uint8Array|Name>} components if a string, parse it as a URI. If a Name, add a deep copy of its components.
+ * Otherwise it is an array of components where each is a string, byte array, ArrayBuffer, Uint8Array or Name.
+ * Convert each and store as an array of Uint8Array. If a component is a string, encode as utf8.
*/
-var Name = function Name(_components){
- if( typeof _components == 'string') {
- if(LOG>3)console.log('Content Name String '+_components);
- this.components = Name.createNameArray(_components);
+var Name = function Name(components) {
+ if( typeof components == 'string') {
+ if(LOG>3)console.log('Content Name String '+components);
+ this.components = Name.createNameArray(components);
}
- else if(typeof _components === 'object'){
+ else if(typeof components === 'object'){
this.components = [];
- if (_components instanceof Name)
- this.add(_components);
- else {
- for (var i = 0; i < _components.length; ++i)
- this.add(_components[i]);
- }
+ if (components instanceof Name)
+ this.add(components);
+ else {
+ for (var i = 0; i < components.length; ++i)
+ this.add(components[i]);
+ }
}
- else if(_components==null)
+ else if(components==null)
this.components =[];
else
if(LOG>1)console.log("NO CONTENT NAME GIVEN");
@@ -37,8 +36,7 @@
return this.to_uri();
};
-/* Parse uri as a URI and return an array of Uint8Array components.
- *
+/** Parse uri as a URI and return an array of Uint8Array components.
*/
Name.createNameArray = function(uri) {
uri = uri.trim();
@@ -118,11 +116,11 @@
return CCNProtocolDTags.Name;
};
-/*
- * component is a string, byte array, ArrayBuffer, Uint8Array or Name.
- * Convert to Uint8Array and add to this Name.
- * If a component is a string, encode as utf8.
+/**
+ * Convert the component to a Uint8Array and add to this Name.
* Return this Name object to allow chaining calls to add.
+ * @param {String|Array<number>|ArrayBuffer|Uint8Array|Name} component If a component is a string, encode as utf8.
+ * @returns {Name}
*/
Name.prototype.add = function(component){
var result;
@@ -160,39 +158,9 @@
};
/**
- * @brief Add component that represents a segment number
- *
- * @param number Segment number (integer is expected)
- *
- * This component has a special format handling:
- * - if number is zero, then %00 is added
- * - if number is between 1 and 255, %00%01 .. %00%FF is added
- * - ...
+ * Return the escaped name string according to "NDNx URI Scheme".
+ * @returns {String}
*/
-Name.prototype.addSegment = function(number) {
- // step 1: figure out how many bytes will be needed
- var bytes = 1; // at least 1 byte
- var test_number = number;
- while (test_number > 0) {
- bytes ++;
- test_number >>= 8;
- }
-
- var result = new Uint8Array (bytes);
- var index = 0;
- result[index] = 0;
- index ++;
- while (number > 0) {
- result[index] = number & 0xFF;
- number >>= 8;
- index ++;
- }
-
- this.components.push(result);
- return this;
-}
-
-// Return the escaped name string according to "CCNx URI Scheme".
Name.prototype.to_uri = function() {
if (this.components.length == 0)
return "/";
@@ -206,15 +174,15 @@
};
/**
-* @brief Add component that represents a segment number
-*
-* @param number Segment number (integer is expected)
-*
-* This component has a special format handling:
-* - if number is zero, then %00 is added
-* - if number is between 1 and 255, %00%01 .. %00%FF is added
-* - ...
-*/
+ * Add a component that represents a segment number
+ *
+ * This component has a special format handling:
+ * - if number is zero, then %00 is added
+ * - if number is between 1 and 255, %00%01 .. %00%FF is added
+ * - ...
+ * @param {number} number the segment number (integer is expected)
+ * @returns {Name}
+ */
Name.prototype.addSegment = function(number) {
var segmentNumberBigEndian = DataUtils.nonNegativeIntToBigEndian(number);
// Put a 0 byte in front.
@@ -225,7 +193,7 @@
return this;
};
-/*
+/**
* Return a new Name with the first nComponents components of this Name.
*/
Name.prototype.getPrefix = function(nComponents) {
@@ -240,7 +208,7 @@
return new Name(this.components.slice(0, this.components.length-1));
}
-/*
+/**
* Return a new ArrayBuffer of the component at i.
*/
Name.prototype.getComponent = function(i) {
@@ -249,7 +217,7 @@
return result;
}
-/*
+/**
* The "file name" in a name is the last component that isn't blank and doesn't start with one of the
* special marker octets (for version, etc.). Return the index in this.components of
* the file name, or -1 if not found.
@@ -270,7 +238,7 @@
return -1;
}
-/*
+/**
* Return true if this Name has the same components as name.
*/
Name.prototype.equalsName = function(name) {
@@ -286,7 +254,7 @@
return true;
}
-/*
+/**
* Find the last component in name that has a ContentDigest and return the digest value as Uint8Array,
* or null if not found. See Name.getComponentContentDigestValue.
*/
@@ -300,7 +268,7 @@
return null;
}
-/*
+/**
* If component is a ContentDigest, return the digest value as a Uint8Array subarray (don't modify!).
* If not a ContentDigest, return null.
* A ContentDigest component is Name.ContentDigestPrefix + 32 bytes + Name.ContentDigestSuffix.
@@ -323,7 +291,7 @@
Name.ContentDigestPrefix = new Uint8Array([0xc1, 0x2e, 0x4d, 0x2e, 0x47, 0xc1, 0x01, 0xaa, 0x02, 0x85]);
Name.ContentDigestSuffix = new Uint8Array([0x00]);
-/*
+/**
* Return component as an escaped string according to "CCNx URI Scheme".
* We can't use encodeURIComponent because that doesn't encode all the characters we want to.
*/
@@ -357,7 +325,7 @@
return result;
};
-/*
+/**
* Return component as a Uint8Array by decoding the escapedString according to "CCNx URI Scheme".
* If escapedString is "", "." or ".." then return null, which means to skip the component in the name.
*/