Source

cappuccino-docs / cappuccino docs / cappuccino.org / learn / documentation / _c_p_range_8j_source.html

Full commit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_range_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:28 GMT -->
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Cappuccino API: Foundation/CPRange.j Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>Foundation/CPRange.j</h1><a href="_c_p_range_8j.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * CPRange.j</span>
<a name="l00003"></a>00003 <span class="comment"> * Foundation</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Created by Francisco Tolmasky.</span>
<a name="l00006"></a>00006 <span class="comment"> * Copyright 2008, 280 North, Inc.</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
<a name="l00009"></a>00009 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span>
<a name="l00010"></a>00010 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00011"></a>00011 <span class="comment"> * version 2.1 of the License, or (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
<a name="l00016"></a>00016 <span class="comment"> * Lesser General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
<a name="l00019"></a>00019 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 
<a name="l00035"></a><a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">00035</a> function <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(location, length)
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037     <span class="keywordflow">return</span> { location: location, length: length };
<a name="l00038"></a>00038 }
<a name="l00039"></a>00039 
<a name="l00046"></a><a class="code" href="group__foundation.html#gae4d4352191524cc80edd4fb130b1495b">00046</a> function <a class="code" href="group__foundation.html#gae4d4352191524cc80edd4fb130b1495b">CPCopyRange</a>(aRange)
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048     <span class="keywordflow">return</span> { location: aRange.location, length: aRange.length };
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 
<a name="l00057"></a><a class="code" href="group__foundation.html#ga757a5d0fb8e3fe1c64330c82e1fa7292">00057</a> function <a class="code" href="group__foundation.html#ga757a5d0fb8e3fe1c64330c82e1fa7292">CPMakeRangeCopy</a>(aRange)
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059     <span class="keywordflow">return</span> { location:aRange.location, length:aRange.length };
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 
<a name="l00068"></a><a class="code" href="group__foundation.html#ga7d819d9828769a45663309ccf26fa3d3">00068</a> function <a class="code" href="group__foundation.html#ga7d819d9828769a45663309ccf26fa3d3">CPEmptyRange</a>(aRange)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070     <span class="keywordflow">return</span> aRange.length === 0;
<a name="l00071"></a>00071 }
<a name="l00072"></a>00072 
<a name="l00079"></a><a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">00079</a> function <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange)
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081     <span class="keywordflow">return</span> aRange.location + aRange.length;
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 
<a name="l00090"></a><a class="code" href="group__foundation.html#ga50f0abfcf83a9786a16a800bdd6e7241">00090</a> function <a class="code" href="group__foundation.html#ga50f0abfcf83a9786a16a800bdd6e7241">CPEqualRanges</a>(lhsRange, rhsRange)
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092     <span class="keywordflow">return</span> ((lhsRange.location === rhsRange.location) &amp;&amp; (lhsRange.length === rhsRange.length));
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
<a name="l00102"></a><a class="code" href="group__foundation.html#ga11d8b85f5a9d54a56c269d269745c671">00102</a> function <a class="code" href="group__foundation.html#ga11d8b85f5a9d54a56c269d269745c671">CPLocationInRange</a>(aLocation, aRange)
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104     <span class="keywordflow">return</span> (aLocation &gt;= aRange.location) &amp;&amp; (aLocation &lt; <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(aRange));
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 
<a name="l00115"></a><a class="code" href="group__foundation.html#gabba35730ec5375f5e23a78da6322f4c9">00115</a> function <a class="code" href="group__foundation.html#gabba35730ec5375f5e23a78da6322f4c9">CPUnionRange</a>(lhsRange, rhsRange)
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117     var location = <a class="code" href="_c_p_obj_j_runtime_8j.html#a4fca277171215842609dc38a6f0c19fb">MIN</a>(lhsRange.location, rhsRange.location);
<a name="l00118"></a>00118         <span class="keywordflow">return</span> <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(location, <a class="code" href="_c_p_obj_j_runtime_8j.html#a45f5f88d061da0c18bcb6b6a854fe898">MAX</a>(<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(lhsRange), <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rhsRange)) - location);
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 
<a name="l00128"></a><a class="code" href="group__foundation.html#ga75c00938ebca2b401aacd063802fdde4">00128</a> function <a class="code" href="group__foundation.html#ga75c00938ebca2b401aacd063802fdde4">CPIntersectionRange</a>(lhsRange, rhsRange)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130     <span class="keywordflow">if</span>(<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(lhsRange) &lt; rhsRange.location || <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rhsRange) &lt; lhsRange.location)
<a name="l00131"></a>00131         <span class="keywordflow">return</span> <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(0, 0);
<a name="l00132"></a>00132         
<a name="l00133"></a>00133     var location = <a class="code" href="_c_p_obj_j_runtime_8j.html#a45f5f88d061da0c18bcb6b6a854fe898">MAX</a>(lhsRange.location, rhsRange.location);
<a name="l00134"></a>00134     <span class="keywordflow">return</span> <a class="code" href="group__foundation.html#ga377fec0972facd19d72b8abcffcdb362">CPMakeRange</a>(location, <a class="code" href="_c_p_obj_j_runtime_8j.html#a4fca277171215842609dc38a6f0c19fb">MIN</a>(<a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(lhsRange), <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rhsRange)) - location);
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 
<a name="l00144"></a><a class="code" href="group__foundation.html#ga27da7cc6d5e82effc742767a75efbe87">00144</a> function <a class="code" href="group__foundation.html#ga27da7cc6d5e82effc742767a75efbe87">CPRangeInRange</a>(lhsRange, rhsRange)
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146     <span class="keywordflow">return</span> (lhsRange.location &lt;= rhsRange.location &amp;&amp; <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(lhsRange) &gt;= <a class="code" href="group__foundation.html#ga9a9c6e53b2b0861cedbb77b5ab72e78f">CPMaxRange</a>(rhsRange));
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 
<a name="l00155"></a><a class="code" href="group__foundation.html#gafaa648e94284213e15f9a4b1ae1b7e0e">00155</a> function <a class="code" href="group__foundation.html#gafaa648e94284213e15f9a4b1ae1b7e0e">CPStringFromRange</a>(aRange)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157     <span class="keywordflow">return</span> <span class="stringliteral">&quot;{&quot;</span> + aRange.location + <span class="stringliteral">&quot;, &quot;</span> + aRange.length + <span class="stringliteral">&quot;}&quot;</span>;
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159 
<a name="l00166"></a><a class="code" href="group__foundation.html#ga3ea8d8570e114b5293740ad51bf43457">00166</a> function <a class="code" href="group__foundation.html#ga3ea8d8570e114b5293740ad51bf43457">CPRangeFromString</a>(aString)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168     var comma = aString.indexOf(<span class="charliteral">&apos;,&apos;</span>);
<a name="l00169"></a>00169     
<a name="l00170"></a>00170     <span class="keywordflow">return</span> { location:parseInt(aString.substr(1, comma - 1)), length:parseInt(aString.substring(comma + 1, aString.length)) };
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172 
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Tue Apr 6 10:32:57 2010 for Cappuccino API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>

<!-- Mirrored from cappuccino.org/learn/documentation/_c_p_range_8j_source.html by HTTrack Website Copier/3.x [XR&CO'2006], Mon, 20 Sep 2010 02:19:28 GMT -->
</html>