1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
// **********************************************************************
//
// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
var Ice = require("../Ice/ModuleRegistry").Ice;
Ice.__M.require(module, [ "../Ice/StringUtil", "../Ice/Identity", "../Ice/LocalException"]);
var StringUtil = Ice.StringUtil;
var Identity = Ice.Identity;
var IdentityParseException = Ice.IdentityParseException;
/**
* Converts a string to an object identity.
*
* @param s The string to convert.
*
* @return The converted object identity.
**/
Ice.stringToIdentity = function(s)
{
var ident = new Identity();
//
// Find unescaped separator; note that the string may contain an escaped
// backslash before the separator.
//
var slash = -1;
var pos = 0;
while((pos = s.indexOf('/', pos)) !== -1)
{
var escapes = 0;
while(pos - escapes > 0 && s.charAt(pos - escapes - 1) == '\\')
{
escapes++;
}
//
// We ignore escaped escapes
//
if(escapes % 2 === 0)
{
if(slash == -1)
{
slash = pos;
}
else
{
//
// Extra unescaped slash found.
//
var ex = new IdentityParseException();
ex.str = "unescaped backslash in identity `" + s + "'";
throw ex;
}
}
pos++;
}
if(slash == -1)
{
ident.category = "";
try
{
ident.name = StringUtil.unescapeString(s);
}
catch(e)
{
var ex = new IdentityParseException();
ex.str = "invalid identity name `" + s + "': " + ex.toString();
throw ex;
}
}
else
{
try
{
ident.category = StringUtil.unescapeString(s, 0, slash);
}
catch(e)
{
var ex = new IdentityParseException();
ex.str = "invalid category in identity `" + s + "': " + ex.toString();
throw ex;
}
if(slash + 1 < s.length)
{
try
{
ident.name = StringUtil.unescapeString(s, slash + 1, s.length);
}
catch(e)
{
var ex = new IdentityParseException();
ex.str = "invalid name in identity `" + s + "': " + ex.toString();
throw ex;
}
}
else
{
ident.name = "";
}
}
return ident;
};
/**
* Converts an object identity to a string.
*
* @param ident The object identity to convert.
*
* @return The string representation of the object identity.
**/
Ice.identityToString = function(ident)
{
if(ident.category === null || ident.category.length === 0)
{
return StringUtil.escapeString(ident.name, "/");
}
else
{
return StringUtil.escapeString(ident.category, "/") + '/' + StringUtil.escapeString(ident.name, "/");
}
};
/**
* Compares the object identities of two proxies.
*
* @param lhs A proxy.
* @param rhs A proxy.
* @return -1 if the identity in <code>lhs</code> compares
* less than the identity in <code>rhs</code>; 0 if the identities
* compare equal; 1, otherwise.
*
* @see ProxyIdentityKey
* @see ProxyIdentityAndFacetKey
* @see ProxyIdentityAndFacetCompare
**/
Ice.proxyIdentityCompare = function(lhs, rhs)
{
if(lhs === rhs)
{
return 0;
}
else if(lhs === null && rhs !== null)
{
return -1;
}
else if(lhs !== null && rhs === null)
{
return 1;
}
else
{
var lhsIdentity = lhs.ice_getIdentity();
var rhsIdentity = rhs.ice_getIdentity();
var n;
if((n = lhsIdentity.name.localeCompare(rhsIdentity.name)) !== 0)
{
return n;
}
return lhsIdentity.category.localeCompare(rhsIdentity.category);
}
};
/**
* Compares the object identities and facets of two proxies.
*
* @param lhs A proxy.
* @param rhs A proxy.
* @return -1 if the identity and facet in <code>lhs</code> compare
* less than the identity and facet in <code>rhs</code>; 0 if the identities
* and facets compare equal; 1, otherwise.
*
* @see ProxyIdentityAndFacetKey
* @see ProxyIdentityKey
* @see ProxyIdentityCompare
**/
Ice.proxyIdentityAndFacetCompare = function(lhs, rhs)
{
if(lhs === rhs)
{
return 0;
}
else if(lhs === null && rhs !== null)
{
return -1;
}
else if(lhs !== null && rhs === null)
{
return 1;
}
else
{
var lhsIdentity = lhs.ice_getIdentity();
var rhsIdentity = rhs.ice_getIdentity();
var n;
if((n = lhsIdentity.name.localeCompare(rhsIdentity.name)) !== 0)
{
return n;
}
if((n = lhsIdentity.category.localeCompare(rhsIdentity.category)) !== 0)
{
return n;
}
var lhsFacet = lhs.ice_getFacet();
var rhsFacet = rhs.ice_getFacet();
if(lhsFacet === null && rhsFacet === null)
{
return 0;
}
else if(lhsFacet === null)
{
return -1;
}
else if(rhsFacet === null)
{
return 1;
}
return lhsFacet.localeCompare(rhsFacet);
}
};
module.exports.Ice = Ice;
|