/// <summary>Get the values of all footer lines with the given key.</summary> /// <remarks>Get the values of all footer lines with the given key.</remarks> /// <param name="keyName">footer key to find values of, case insensitive.</param> /// <returns> /// values of footers with key of /// <code>keyName</code> /// , ordered by their /// order of appearance. Duplicates may be returned if the same /// footer appeared more than once. Empty list if no footers appear /// with the specified key, or there are no footers at all. /// </returns> /// <seealso cref="GetFooterLines()">GetFooterLines()</seealso> public IList <string> GetFooterLines(FooterKey keyName) { IList <FooterLine> src = GetFooterLines(); if (src.IsEmpty()) { return(Sharpen.Collections.EmptyList <string>()); } AList <string> r = new AList <string>(src.Count); foreach (FooterLine f in src) { if (f.Matches(keyName)) { r.AddItem(f.GetValue()); } } return(r); }
public virtual void TestMatchesBugId() { RevCommit commit = Parse("this is a commit subject for test\n" + "\n" + "Simple-Bug-Id: 42\n" ); // paragraph break, now footers appear in final block IList <FooterLine> footers = commit.GetFooterLines(); NUnit.Framework.Assert.IsNotNull(footers); NUnit.Framework.Assert.AreEqual(1, footers.Count); FooterLine line = footers[0]; NUnit.Framework.Assert.IsNotNull(line); NUnit.Framework.Assert.AreEqual("Simple-Bug-Id", line.GetKey()); NUnit.Framework.Assert.AreEqual("42", line.GetValue()); FooterKey bugid = new FooterKey("Simple-Bug-Id"); NUnit.Framework.Assert.IsTrue(line.Matches(bugid), "matches Simple-Bug-Id"); NUnit.Framework.Assert.IsFalse(line.Matches(FooterKey.SIGNED_OFF_BY), "not Signed-off-by" ); NUnit.Framework.Assert.IsFalse(line.Matches(FooterKey.CC), "not CC"); }
/// <param name="key">key to test this line's key name against.</param> /// <returns> /// true if /// <code>key.getName().equalsIgnorecase(getKey())</code> /// . /// </returns> public bool Matches(FooterKey key) { byte[] kRaw = key.raw; int len = kRaw.Length; int bPtr = keyStart; if (keyEnd - bPtr != len) { return(false); } for (int kPtr = 0; kPtr < len;) { byte b = buffer[bPtr++]; if ('A' <= b && ((sbyte)b) <= 'Z') { b += (byte)('a') - (byte)('A'); } if (b != kRaw[kPtr++]) { return(false); } } return(true); }
/// <param name="key">key to test this line's key name against.</param> /// <returns> /// true if /// <code>key.getName().equalsIgnorecase(getKey())</code> /// . /// </returns> public bool Matches(FooterKey key) { byte[] kRaw = key.raw; int len = kRaw.Length; int bPtr = keyStart; if (keyEnd - bPtr != len) { return false; } for (int kPtr = 0; kPtr < len; ) { byte b = buffer[bPtr++]; if ('A' <= b && ((sbyte)b) <= 'Z') { b += (byte)('a') - (byte)('A'); } if (b != kRaw[kPtr++]) { return false; } } return true; }
/// <summary>Get the values of all footer lines with the given key.</summary> /// <remarks>Get the values of all footer lines with the given key.</remarks> /// <param name="keyName">footer key to find values of, case insensitive.</param> /// <returns> /// values of footers with key of /// <code>keyName</code> /// , ordered by their /// order of appearance. Duplicates may be returned if the same /// footer appeared more than once. Empty list if no footers appear /// with the specified key, or there are no footers at all. /// </returns> /// <seealso cref="GetFooterLines()">GetFooterLines()</seealso> public IList<string> GetFooterLines(FooterKey keyName) { IList<FooterLine> src = GetFooterLines(); if (src.IsEmpty()) { return Sharpen.Collections.EmptyList<string>(); } AList<string> r = new AList<string>(src.Count); foreach (FooterLine f in src) { if (f.Matches(keyName)) { r.AddItem(f.GetValue()); } } return r; }
public virtual void TestMatchesBugId() { RevCommit commit = Parse("this is a commit subject for test\n" + "\n" + "Simple-Bug-Id: 42\n" ); // paragraph break, now footers appear in final block IList<FooterLine> footers = commit.GetFooterLines(); NUnit.Framework.Assert.IsNotNull(footers); NUnit.Framework.Assert.AreEqual(1, footers.Count); FooterLine line = footers[0]; NUnit.Framework.Assert.IsNotNull(line); NUnit.Framework.Assert.AreEqual("Simple-Bug-Id", line.GetKey()); NUnit.Framework.Assert.AreEqual("42", line.GetValue()); FooterKey bugid = new FooterKey("Simple-Bug-Id"); NUnit.Framework.Assert.IsTrue(line.Matches(bugid), "matches Simple-Bug-Id"); NUnit.Framework.Assert.IsFalse(line.Matches(FooterKey.SIGNED_OFF_BY), "not Signed-off-by" ); NUnit.Framework.Assert.IsFalse(line.Matches(FooterKey.CC), "not CC"); }