public override int evalNodeSet(VTDNav vn) { // TODO Auto-generated method stub int i = -1; if (cached) { if (count < ens.size_Renamed_Field) { i = ens.intAt(count); vn.recoverNode(i); count++; return(i); } else { return(-1); } } else { cached = true; if (ens == null) { ens = new FastIntBuffer(8);//page size 64 } //record node set while ((i = e.evalNodeSet(vn)) != -1) { ens.append(i); } e.reset(vn); if (ens.size_Renamed_Field > 0) { i = ens.intAt(count);//count should be zero vn.recoverNode(i); count++; return(i); } else { return(-1); } } }
private bool compNodeSetNodeSet(Expr left, Expr right, VTDNav vn, int op) { int i, i1 = 0, stackSize, s1; try { if (fib1 == null) { fib1 = new FastIntBuffer(BUF_SZ_EXP); } vn.push2(); stackSize = vn.contextStack2.size; while ((i = left.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn, i); if (i1 != -1) { fib1.append(i1); } } left.reset(vn); vn.contextStack2.size = stackSize; vn.pop2(); vn.push2(); stackSize = vn.contextStack2.size; while ((i = right.evalNodeSet(vn)) != -1) { i1 = getStringVal(vn, i); if (i1 != -1) { s1 = fib1.size_Renamed_Field; for (int k = 0; k < s1; k++) { bool b = compareVV(fib1.intAt(k), vn, i1, op); if (b) { fib1.size_Renamed_Field = 0; vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); return(true); } } } } vn.contextStack2.size = stackSize; vn.pop2(); right.reset(vn); fib1.size_Renamed_Field = 0; return(false); } catch (Exception e) { fib1.size_Renamed_Field = 0; throw new System.SystemException("Undefined behavior"); } }
protected internal bool checkNsUniqueness(int i) { for (int j = 0; j < fib.size_Renamed_Field; j++) { if (vn.compareTokens(fib.intAt(j), vn, i) == 0) { return(false); } } fib.append(i); return(true); }
/// <summary> /// This function is called within VTDGen and /// VTDNav's writeIndex /// </summary> /// <param name="version"></param> /// <param name="encodingType"></param> /// <param name="ns"></param> /// <param name="byteOrder"></param> /// <param name="nestDepth"></param> /// <param name="LCLevel"></param> /// <param name="rootIndex"></param> /// <param name="xmlDoc"></param> /// <param name="docOffset"></param> /// <param name="docLen"></param> /// <param name="vtdBuffer"></param> /// <param name="l1Buffer"></param> /// <param name="l2Buffer"></param> /// <param name="l3Buffer"></param> /// <param name="os"></param> /// <returns></returns> public static void writeIndex_L3(byte version, int encodingType, bool ns, bool byteOrder, int nestDepth, int LCLevel, int rootIndex, byte[] xmlDoc, int docOffset, int docLen, FastLongBuffer vtdBuffer, FastLongBuffer l1Buffer, FastLongBuffer l2Buffer, FastIntBuffer l3Buffer, System.IO.Stream os) { if (xmlDoc == null || docLen <= 0 || vtdBuffer == null || l1Buffer == null || l2Buffer == null || l3Buffer == null || LCLevel != 3) { throw new System.ArgumentException("Invalid argument for writeIndex "); } if (vtdBuffer.size_Renamed_Field == 0) { throw new IndexWriteException("VTDBuffer can't be zero length"); } int i; System.IO.BinaryWriter dos = new System.IO.BinaryWriter(os); // first 4 bytes byte[] ba = new byte[4]; ba[0] = (byte)version; // version # is 1 ba[1] = (byte)encodingType; if (BitConverter.IsLittleEndian == false) ba[2] = (byte)(ns ? 0xe0 : 0xa0); // big endien else ba[2] = (byte)(ns ? 0xc0 : 0x80); ba[3] = (byte)nestDepth; dos.Write(ba); // second 4 bytes ba[0] = 0; ba[1] = 4; ba[2] = (byte)((rootIndex & 0xff00) >> 8); ba[3] = (byte)(rootIndex & 0xff); dos.Write(ba); // 2 reserved 32-bit words set to zero ba[1] = ba[2] = ba[3] = 0; dos.Write(ba); dos.Write(ba); dos.Write(ba); dos.Write(ba); // write XML doc in bytes dos.Write((long)docLen); dos.Write(xmlDoc, docOffset, docLen); //dos.Write(xmlDoc, docOffset, docLen); // zero padding to make it integer multiple of 64 bits if ((docLen & 0x07) != 0) { int t = (((docLen >> 3) + 1) << 3) - docLen; for (; t > 0; t--) dos.Write((System.Byte)0); } // write VTD dos.Write((long)vtdBuffer.size_Renamed_Field); if (docOffset != 0) { for (i = 0; i < vtdBuffer.size_Renamed_Field; i++) { dos.Write(adjust(vtdBuffer.longAt(i), -docOffset)); } } else { for (i = 0; i < vtdBuffer.size_Renamed_Field; i++) { dos.Write(vtdBuffer.longAt(i)); } } // write L1 dos.Write((long)l1Buffer.size_Renamed_Field); for (i = 0; i < l1Buffer.size_Renamed_Field; i++) { dos.Write(l1Buffer.longAt(i)); } // write L2 dos.Write((long)l2Buffer.size_Renamed_Field); for (i = 0; i < l2Buffer.size_Renamed_Field; i++) { dos.Write(l2Buffer.longAt(i)); } // write L3 dos.Write((long)l3Buffer.size_Renamed_Field); for (i = 0; i < l3Buffer.size_Renamed_Field; i++) { dos.Write(l3Buffer.intAt(i)); } // pad zero if # of l3 entry is odd if ((l3Buffer.size_Renamed_Field & 1) != 0) dos.Write(0); dos.Close(); }
/// <summary> /// /// </summary> /// <returns></returns> public ElementFragmentNs getElementFragmentNs() { if (this.ns == false) throw new NavException("getElementFragmentNS can only be called "); FastIntBuffer fib = new FastIntBuffer(3); // init size 8 //fill the fib with integer // first get the list of name space nodes int[] ia = context; int d = ia[0]; // -1 for document node, 0 for root element; int c = getCurrentIndex2(); int len = (c == 0 || c == rootIndex) ? 0 : (getTokenLength(c) & 0xffff); // get the length of qualified node // put the neighboring ATTR_NS nodes into the array // and record the total # of them int i = 0; int count = 0; if (d > 0) { // depth > 0 every node except document and root element int k = getCurrentIndex2() + 1; if (k < this.vtdSize) { while (k < this.vtdSize) { int type = this.getTokenType(k); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { if (type == VTDNav.TOKEN_ATTR_NS) { fib.append(k); //System.out.println(" ns name ==>" + toString(k)); } k += 2; } else break; //type = this.getTokenType(k); } } count = fib.size_Renamed_Field; d--; while (d >= 0) { // then search for ns node in the vinicity of the ancestor nodes if (d > 0) { // starting point k = ia[d] + 1; } else { // starting point k = this.rootIndex + 1; } if (k < this.vtdSize) { while (k < this.vtdSize) { int type = this.getTokenType(k); if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) { bool unique = true; if (type == VTDNav.TOKEN_ATTR_NS) { for (int z = 0; z < fib.size_Renamed_Field; z++) { //System.out.println("fib size ==> "+fib.size_Renamed_Field); //if (fib.size_Renamed_Field == 4) ; if (matchTokens(fib.intAt(z), this, k)) { unique = false; break; } } if (unique) fib.append(k); } } k += 2; //type = this.getTokenType(k); } } d--; } // System.out.println("count ===> "+count); // then restore the name space node by shifting the array int newSz = fib.size_Renamed_Field - count; for (i = 0; i < newSz; i++) { fib.modifyEntry(i, fib.intAt(i + count)); } fib.size_Renamed_Field = newSz; } long l = getElementFragment(); return new ElementFragmentNs(this, l, fib, len); }
/// <summary> Return a byte array with namespace compensation /// witht the orginal encoding format /// </summary> /// <returns> /// /// </returns> public byte[] toBytes() { byte[] ba = new byte[Size]; int os = (int)l; int len = (int)(l >> 32); int os1 = 0; byte[] xml = vn.getXML().getBytes(); if (stLen == 0) { Array.Copy(xml, os, ba, 0, len); return(ba); } int enc = vn.getEncoding(); int temp = 0; switch (enc) { case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp = (stLen + 1) << 1; break; default: temp = stLen + 1; break; } Array.Copy(xml, os, ba, 0, temp); //namespace compensation os1 += temp; int tos = 0, tlen = 0; for (int i = 0; i < fib.size_Renamed_Field; i++) { //System.out.println("i ==>"+fib.intAt(i)); switch (enc) { case VTDNav.FORMAT_UTF_16BE: Array.Copy(ws, 0, ba, os1, 2); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i)) << 1; tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff) << 1; Array.Copy(xml, tos, ba, os1, tlen); os1 += tlen; Array.Copy(ws, 2, ba, os1, 2); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i) + 1) - 1) << 1; tlen = ((vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2) << 1; Array.Copy(xml, tos, ba, os1, tlen); os1 += tlen; break; case VTDNav.FORMAT_UTF_16LE: Array.Copy(ws, 1, ba, os1, 2); os1 += 2; tos = vn.getTokenOffset(fib.intAt(i)) << 1; tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff) << 1; Array.Copy(xml, tos, ba, os1, tlen); os1 += tlen; Array.Copy(ws, 3, ba, os1, 2); os1 += 2; tos = (vn.getTokenOffset(fib.intAt(i) + 1) - 1) << 1; tlen = ((vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2) << 1; Array.Copy(xml, tos, ba, os1, tlen); os1 += tlen; break; default: Array.Copy(ws, 1, ba, os1, 1); os1++; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); Array.Copy(xml, tos, ba, os1, tlen); os1 += tlen; Array.Copy(ws, 3, ba, os1, 1); os1++; tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2; Array.Copy(xml, tos, ba, os1, tlen); os1 += tlen; break; } } switch (enc) { case VTDNav.FORMAT_UTF_16BE: case VTDNav.FORMAT_UTF_16LE: temp = (stLen + 1) << 1; break; default: temp = stLen + 1; break; } Array.Copy(xml, os + temp, ba, os1, len - temp); return(ba); }
/// <summary> /// /// This method set the cursor in VTDNav to the nodes as recorded /// in NodeRecorder, and return the output of "getCurrentIndex()" /// It is important to notice that you can only go forward, not /// backward /// /// </summary> /// <returns> @return int</returns> public int iterate() { int j, i; if (count < fib.size_Renamed_Field) { i = fib.intAt(count); bool b = (i >= 0); if (b == false) { i = i & 0x7fffffff; } switch (i) { case 0xff: vn.context[0] = -1; vn.atTerminal = false; count++; break; case 0: vn.context[0] = 0; if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 1); count += 2; } else { vn.atTerminal = false; count++; } break; case 1: vn.context[0] = 1; vn.context[1] = fib.intAt(count + 1); vn.l1index = fib.intAt(count + 2); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 3); count += 4; } else { vn.atTerminal = false; count += 3; } break; case 2: vn.context[0] = 2; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.l1index = fib.intAt(count + 3); vn.l2lower = fib.intAt(count + 4); vn.l2upper = fib.intAt(count + 5); vn.l2index = fib.intAt(count + 6); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 7); count += 8; } else { vn.atTerminal = false; count += 7; } break; case 3: vn.context[0] = 3; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.l1index = fib.intAt(count + 4); vn.l2lower = fib.intAt(count + 5); vn.l2upper = fib.intAt(count + 6); vn.l2index = fib.intAt(count + 7); vn.l3lower = fib.intAt(count + 8); vn.l3upper = fib.intAt(count + 9); vn.l3index = fib.intAt(count + 10); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 11); count += 12; } else { vn.atTerminal = false; count += 11; } break; default: if (vn.shallowDepth) { // vn.context[0] = i; for (j = 0; j < i; j++) { vn.context[j] = fib.intAt(count + j); } vn.l1index = fib.intAt(count + i); vn.l2lower = fib.intAt(count + i + 1); vn.l2upper = fib.intAt(count + i + 2); vn.l2index = fib.intAt(count + i + 3); vn.l3lower = fib.intAt(count + i + 4); vn.l3upper = fib.intAt(count + i + 5); vn.l3index = fib.intAt(count + i + 6); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 11); count += i + 9; } else { vn.atTerminal = false; count += i + 8; } break; } else { VTDNav_L5 vnl = (VTDNav_L5)vn; switch (i) { case 4: vn.context[0] = 4; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.context[4] = fib.intAt(count + 4); vn.l1index = fib.intAt(count + 5); vn.l2lower = fib.intAt(count + 6); vn.l2upper = fib.intAt(count + 7); vn.l2index = fib.intAt(count + 8); vn.l3lower = fib.intAt(count + 9); vn.l3upper = fib.intAt(count + 10); vn.l3index = fib.intAt(count + 11); vnl.l4lower = fib.intAt(count + 12); vnl.l4upper = fib.intAt(count + 13); vnl.l4index = fib.intAt(count + 14); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 15); count += 16; } else { vn.atTerminal = false; count += 15; } break; case 5: vn.context[0] = 5; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.context[4] = fib.intAt(count + 4); vn.context[5] = fib.intAt(count + 5); vn.l1index = fib.intAt(count + 6); vn.l2lower = fib.intAt(count + 7); vn.l2upper = fib.intAt(count + 8); vn.l2index = fib.intAt(count + 9); vn.l3lower = fib.intAt(count + 10); vn.l3upper = fib.intAt(count + 11); vn.l3index = fib.intAt(count + 12); vnl.l4lower = fib.intAt(count + 13); vnl.l4upper = fib.intAt(count + 14); vnl.l4index = fib.intAt(count + 15); vnl.l5lower = fib.intAt(count + 16); vnl.l5upper = fib.intAt(count + 17); vnl.l5index = fib.intAt(count + 18); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 19); count += 20; } else { vn.atTerminal = false; count += 19; } break; default: vn.context[0] = i; for (j = 1; j < i; j++) { vn.context[j] = fib.intAt(count + j); } vn.l1index = fib.intAt(count + i); vn.l2lower = fib.intAt(count + i + 1); vn.l2upper = fib.intAt(count + i + 2); vn.l2index = fib.intAt(count + i + 3); vn.l3lower = fib.intAt(count + i + 4); vn.l3upper = fib.intAt(count + i + 5); vn.l3index = fib.intAt(count + i + 6); vnl.l4lower = fib.intAt(count + i + 7); vnl.l4upper = fib.intAt(count + i + 8); vnl.l4index = fib.intAt(count + i + 9); vnl.l5lower = fib.intAt(count + i + 10); vnl.l5upper = fib.intAt(count + i + 11); vnl.l5index = fib.intAt(count + i + 12); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + i + 13); count += i + 15; } else { vn.atTerminal = false; count += i + 14; } break; } } break; } position++; return(vn.getCurrentIndex()); } return(-1); }
/// <summary> /// This function is called within VTDGen and /// VTDNav's writeIndex /// </summary> /// <param name="version"></param> /// <param name="encodingType"></param> /// <param name="ns"></param> /// <param name="byteOrder"></param> /// <param name="nestDepth"></param> /// <param name="LCLevel"></param> /// <param name="rootIndex"></param> /// <param name="xmlDoc"></param> /// <param name="docOffset"></param> /// <param name="docLen"></param> /// <param name="vtdBuffer"></param> /// <param name="l1Buffer"></param> /// <param name="l2Buffer"></param> /// <param name="l3Buffer"></param> /// <param name="os"></param> /// <returns></returns> public static void writeIndex_L3(byte version, int encodingType, bool ns, bool byteOrder, int nestDepth, int LCLevel, int rootIndex, byte[] xmlDoc, int docOffset, int docLen, FastLongBuffer vtdBuffer, FastLongBuffer l1Buffer, FastLongBuffer l2Buffer, FastIntBuffer l3Buffer, System.IO.Stream os) { if (xmlDoc == null || docLen <= 0 || vtdBuffer == null || l1Buffer == null || l2Buffer == null || l3Buffer == null || LCLevel != 3) { throw new System.ArgumentException("Invalid argument for writeIndex "); } if (vtdBuffer.size_Renamed_Field == 0) { throw new IndexWriteException("VTDBuffer can't be zero length"); } int i; System.IO.BinaryWriter dos = new System.IO.BinaryWriter(os); // first 4 bytes byte[] ba = new byte[4]; ba[0] = (byte)version; // version # is 1 ba[1] = (byte)encodingType; if (BitConverter.IsLittleEndian == false) { ba[2] = (byte)(ns ? 0xe0 : 0xa0); // big endien } else { ba[2] = (byte)(ns ? 0xc0 : 0x80); } ba[3] = (byte)nestDepth; dos.Write(ba); // second 4 bytes ba[0] = 0; ba[1] = 4; ba[2] = (byte)((rootIndex & 0xff00) >> 8); ba[3] = (byte)(rootIndex & 0xff); dos.Write(ba); // 2 reserved 32-bit words set to zero ba[1] = ba[2] = ba[3] = 0; dos.Write(ba); dos.Write(ba); dos.Write(ba); dos.Write(ba); // write XML doc in bytes dos.Write((long)docLen); dos.Write(xmlDoc, docOffset, docLen); //dos.Write(xmlDoc, docOffset, docLen); // zero padding to make it integer multiple of 64 bits if ((docLen & 0x07) != 0) { int t = (((docLen >> 3) + 1) << 3) - docLen; for (; t > 0; t--) { dos.Write((System.Byte) 0); } } // write VTD dos.Write((long)vtdBuffer.size_Renamed_Field); if (docOffset != 0) { for (i = 0; i < vtdBuffer.size_Renamed_Field; i++) { dos.Write(adjust(vtdBuffer.longAt(i), -docOffset)); } } else { for (i = 0; i < vtdBuffer.size_Renamed_Field; i++) { dos.Write(vtdBuffer.longAt(i)); } } // write L1 dos.Write((long)l1Buffer.size_Renamed_Field); for (i = 0; i < l1Buffer.size_Renamed_Field; i++) { dos.Write(l1Buffer.longAt(i)); } // write L2 dos.Write((long)l2Buffer.size_Renamed_Field); for (i = 0; i < l2Buffer.size_Renamed_Field; i++) { dos.Write(l2Buffer.longAt(i)); } // write L3 dos.Write((long)l3Buffer.size_Renamed_Field); for (i = 0; i < l3Buffer.size_Renamed_Field; i++) { dos.Write(l3Buffer.intAt(i)); } // pad zero if # of l3 entry is odd if ((l3Buffer.size_Renamed_Field & 1) != 0) { dos.Write(0); } dos.Close(); }
/// <summary> /// /// This method set the cursor in VTDNav to the nodes as recorded /// in NodeRecorder, and return the output of "getCurrentIndex()" /// It is important to notice that you can only go forward, not /// backward /// /// </summary> /// <returns> @return int</returns> public int iterate() { int j, i; if (count < fib.size()) { i = fib.intAt(count); bool b = (i >= 0); if (b == false) { i = i & 0x7fffffff; } switch (i) { case 0xff: vn.context[0] = -1; vn.atTerminal = false; count++; break; case 0: vn.context[0] = 0; if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 1); count += 2; } else { vn.atTerminal = false; count++; } break; case 1: vn.context[0] = 1; vn.context[1] = fib.intAt(count + 1); vn.l1index = fib.intAt(count + 2); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 3); count += 4; } else { vn.atTerminal = false; count += 3; } break; case 2: vn.context[0] = 2; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.l1index = fib.intAt(count + 3); vn.l2lower = fib.intAt(count + 4); vn.l2upper = fib.intAt(count + 5); vn.l2index = fib.intAt(count + 6); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 7); count += 8; } else { vn.atTerminal = false; count += 7; } break; case 3: vn.context[0] = 3; vn.context[1] = fib.intAt(count + 1); vn.context[2] = fib.intAt(count + 2); vn.context[3] = fib.intAt(count + 3); vn.l1index = fib.intAt(count + 4); vn.l2lower = fib.intAt(count + 5); vn.l2upper = fib.intAt(count + 6); vn.l2index = fib.intAt(count + 7); vn.l3lower = fib.intAt(count + 8); vn.l3upper = fib.intAt(count + 9); vn.l3index = fib.intAt(count + 10); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 11); count += 12; } else { vn.atTerminal = false; count += 11; } break; default: vn.context[0] = i; for (j = 1; j < i; j++) { vn.context[j] = fib.intAt(count + j); } vn.l1index = fib.intAt(count + i); vn.l2lower = fib.intAt(count + i + 1); vn.l2upper = fib.intAt(count + i + 2); vn.l2index = fib.intAt(count + i + 3); vn.l3lower = fib.intAt(count + i + 4); vn.l3upper = fib.intAt(count + i + 5); vn.l3index = fib.intAt(count + i + 6); if (b == false) { vn.atTerminal = true; vn.LN = fib.intAt(count + 11); count += i + 8; } else { vn.atTerminal = false; count += i + 7; } break; } position++; return(vn.getCurrentIndex()); } return(-1); }