hsfm/src/HSFM-GUI-Glib-GlibString.html
2016-06-01 19:32:51 +02:00

92 lines
10 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>src/HSFM/GUI/Glib/GlibString.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{--
<a name="line-2"></a>HSFM, a filemanager written in Haskell.
<a name="line-3"></a>Copyright (C) 2016 Julian Ospald
<a name="line-4"></a>
<a name="line-5"></a>This program is free software; you can redistribute it and/or
<a name="line-6"></a>modify it under the terms of the GNU General Public License
<a name="line-7"></a>version 2 as published by the Free Software Foundation.
<a name="line-8"></a>
<a name="line-9"></a>This program is distributed in the hope that it will be useful,
<a name="line-10"></a>but WITHOUT ANY WARRANTY; without even the implied warranty of
<a name="line-11"></a>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
<a name="line-12"></a>GNU General Public License for more details.
<a name="line-13"></a>
<a name="line-14"></a>You should have received a copy of the GNU General Public License
<a name="line-15"></a>along with this program; if not, write to the Free Software
<a name="line-16"></a>Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<a name="line-17"></a>--}</span>
<a name="line-18"></a>
<a name="line-19"></a><span class='hs-comment'>{-# LANGUAGE OverloadedStrings #-}</span>
<a name="line-20"></a><span class='hs-comment'>{-# OPTIONS_HADDOCK ignore-exports #-}</span>
<a name="line-21"></a>
<a name="line-22"></a>
<a name="line-23"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>HSFM</span><span class='hs-varop'>.</span><span class='hs-conid'>GUI</span><span class='hs-varop'>.</span><span class='hs-conid'>Glib</span><span class='hs-varop'>.</span><span class='hs-conid'>GlibString</span> <span class='hs-keyword'>where</span>
<a name="line-24"></a>
<a name="line-25"></a>
<a name="line-26"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>BS</span>
<a name="line-27"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>UTF8</span>
<a name="line-28"></a> <span class='hs-layout'>(</span>
<a name="line-29"></a> <span class='hs-varid'>toString</span>
<a name="line-30"></a> <span class='hs-layout'>)</span>
<a name="line-31"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Word8</span>
<a name="line-32"></a> <span class='hs-layout'>(</span>
<a name="line-33"></a> <span class='hs-sel'>_percent</span>
<a name="line-34"></a> <span class='hs-layout'>)</span>
<a name="line-35"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>C</span><span class='hs-varop'>.</span><span class='hs-conid'>String</span>
<a name="line-36"></a> <span class='hs-layout'>(</span>
<a name="line-37"></a> <span class='hs-conid'>CStringLen</span>
<a name="line-38"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>CString</span>
<a name="line-39"></a> <span class='hs-layout'>)</span>
<a name="line-40"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>C</span><span class='hs-varop'>.</span><span class='hs-conid'>Types</span>
<a name="line-41"></a> <span class='hs-layout'>(</span>
<a name="line-42"></a> <span class='hs-conid'>CSize</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span>
<a name="line-43"></a> <span class='hs-layout'>)</span>
<a name="line-44"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshal</span><span class='hs-varop'>.</span><span class='hs-conid'>Utils</span>
<a name="line-45"></a> <span class='hs-layout'>(</span>
<a name="line-46"></a> <span class='hs-varid'>maybePeek</span>
<a name="line-47"></a> <span class='hs-layout'>)</span>
<a name="line-48"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Ptr</span>
<a name="line-49"></a> <span class='hs-layout'>(</span>
<a name="line-50"></a> <span class='hs-varid'>nullPtr</span>
<a name="line-51"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>plusPtr</span>
<a name="line-52"></a> <span class='hs-layout'>)</span>
<a name="line-53"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>Glib</span><span class='hs-varop'>.</span><span class='hs-conid'>UTFString</span>
<a name="line-54"></a>
<a name="line-55"></a>
<a name="line-56"></a>
<a name="line-57"></a><a name="instance%20GlibString%20BS.ByteString"></a><span class='hs-comment'>-- TODO: move this to its own module</span>
<a name="line-58"></a><a name="instance%20GlibString%20BS.ByteString"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>GlibString</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>where</span>
<a name="line-59"></a> <span class='hs-varid'>withUTFString</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>useAsCString</span>
<a name="line-60"></a> <span class='hs-varid'>withUTFStringLen</span> <span class='hs-varid'>s</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>useAsCStringLen</span> <span class='hs-varid'>s</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varop'>.</span> <span class='hs-varid'>noNullPtrs</span><span class='hs-layout'>)</span>
<a name="line-61"></a> <span class='hs-varid'>peekUTFString</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-62"></a> <span class='hs-varid'>len</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-varid'>c_strlen</span> <span class='hs-varid'>s</span>
<a name="line-63"></a> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>packCStringLen</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span> <span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>len</span><span class='hs-layout'>)</span>
<a name="line-64"></a> <span class='hs-varid'>maybePeekUTFString</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>maybePeek</span> <span class='hs-varid'>peekUTFString</span>
<a name="line-65"></a> <span class='hs-varid'>peekUTFStringLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>packCStringLen</span>
<a name="line-66"></a> <span class='hs-varid'>newUTFString</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>newUTFString</span> <span class='hs-varop'>.</span> <span class='hs-varid'>toString</span>
<a name="line-67"></a> <span class='hs-varid'>newUTFStringLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>newUTFStringLen</span> <span class='hs-varop'>.</span> <span class='hs-varid'>toString</span>
<a name="line-68"></a> <span class='hs-varid'>genUTFOfs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>genUTFOfs</span> <span class='hs-varop'>.</span> <span class='hs-varid'>toString</span>
<a name="line-69"></a> <span class='hs-varid'>stringLength</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>length</span>
<a name="line-70"></a> <span class='hs-varid'>unPrintf</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>intercalate</span> <span class='hs-str'>"%%"</span> <span class='hs-layout'>(</span><span class='hs-conid'>BS</span><span class='hs-varop'>.</span><span class='hs-varid'>split</span> <span class='hs-sel'>_percent</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span>
<a name="line-71"></a>
<a name="line-72"></a>
<a name="line-73"></a><span class='hs-keyword'>foreign</span> <span class='hs-keyword'>import</span> <span class='hs-keyword'>ccall</span> <span class='hs-keyword'>unsafe</span> <span class='hs-str'>"string.h strlen"</span> <span class='hs-varid'>c_strlen</span>
<a name="line-74"></a> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>CString</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>IO</span> <span class='hs-conid'>CSize</span>
<a name="line-75"></a>
<a name="line-76"></a>
<a name="line-77"></a><a name="noNullPtrs"></a><span class='hs-definition'>noNullPtrs</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>CStringLen</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>CStringLen</span>
<a name="line-78"></a><span class='hs-definition'>noNullPtrs</span> <span class='hs-layout'>(</span><span class='hs-varid'>p</span><span class='hs-layout'>,</span> <span class='hs-num'>0</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>p</span> <span class='hs-varop'>==</span> <span class='hs-varid'>nullPtr</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>plusPtr</span> <span class='hs-varid'>p</span> <span class='hs-num'>1</span><span class='hs-layout'>,</span> <span class='hs-num'>0</span><span class='hs-layout'>)</span>
<a name="line-79"></a><span class='hs-definition'>noNullPtrs</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>s</span>
<a name="line-80"></a>
</pre></body>
</html>