UTF-8 Validation for REALbasic

· Mar 6, 12:14 PM

In response to a question and ensuing discussion on the REALbasic NUG, I wrote a function to validate UTF-8 text as defined by RFC 3629.

More...

---

Current Reading

· Feb 25, 01:25 PM

I could have used this book a few years ago.

---

REALbasic's Secret String Buffer

· Feb 21, 11:19 AM

From time to time, people ask for a mutable string class in REALbasic. As it turns out, REALbasic already has one. It is not feature-complete, but with the addition of a few extension methods, it can be complete with the features you want. The class is BinaryStream.

More...

Comment [1]

---

Release Note Browser 1.0b029 Released

· Feb 10, 11:18 AM

Lars Jensen has released a new version of Release Note Browser, a must-have tool for anyone using REALbasic.

Release Note Browser

---

Listbox Subclass Example

· Feb 9, 09:39 PM

I’ve uploaded a little example project that I wrote in the course of answering a question on the NUG.

ListboxSubclassExample demonstrates how to override Listbox.Cell and add an event to be called when the value of a cell is changed by assigning to Cell.

Download

---

FolderItem.CopyFileTo in Linux

· Jan 13, 10:37 AM

It appears that in Linux builds, FolderItem.CopyFileTo is implemented by calling cp. The implementation has an undocumented side effect: cp error messages are written to stderr.

---

RbScript Plugins for REALbasic Applications

· Dec 31, 09:09 PM

The most useful thing you will read this holiday season is this tutorial by Thomas Tempelmann on designing REALbasic applications that support plugins written in RbScript.

---

Sorting Boolean Arrays

· Dec 26, 03:48 PM

Lots of spare-time projects to choose from on a free day for me left me in a state of indecision. So I decided to take some old mathematics advice and compute the simplest thing I don’t already know. Today, that happens to be the code for sorting a Boolean array.

First is a function to test sortedness.

Function IsSorted(extends b() as Boolean) As Boolean
  dim theResult as Boolean = true
  
  dim firstTrueIndex as Integer = 1 + UBound(b)
  for i as Integer = 0 to UBound(b)
    if b(i) then
      firstTrueIndex = i
      exit
    end if
  next
  
  for i as Integer = firstTrueIndex to UBound(b)
    if not b(i) then
      theResult = false
      exit
    end if
  next
  
  return theResult
End Function

The sorting code uses a standard idea; one scans the array from left and right, swapping out-of-order elements until the pointers cross.

Sub Sort(extends b() as Boolean)
  dim leftPtr as Integer = 0
  dim rightPtr as Integer = UBound(b) 
  
  do
    while leftPtr < rightPtr
      if not b(leftPtr) then
        leftPtr = leftPtr + 1
      else
        exit
      end if
    wend
  
    while rightPtr > leftPtr
      if b(rightPtr) then
        rightPtr = rightPtr - 1
      else
        exit
      end if
    wend
  
    if leftPtr < rightPtr then
      b(leftPtr) = false
      b(rightPtr) = true
      leftPtr = leftPtr + 1
      rightPtr = rightPtr - 1
    else
      exit
    end if
  loop
End Sub

This code is a little more subtle than a first glance might reveal, and I’m not telling whether or not I got it on the first try. If you have an interest in learning quicksort, this code might serve as a useful warmup for following the partition code.

Comment [2]

---

Current Reading

· Dec 5, 09:35 AM

Crash-Only Software PDF HTML

On Designing and Deploying Internet-Scale Services PDF HTML

Comment [2]

---

Get the Mac OS Processor Architecture at Runtime

· Dec 3, 10:04 AM

Apparently it is of interest to some developers to know whether a Mac OS application is running on an Intel or PPC machine. The REALbasic target* constants do not tell you this; they tell you the platform(s) for which the executable was compiled.

While you can make reasonable guesses using tricks, the processor architecture information is easily retrieved at runtime using the BSD function NXGetLocalArchInfo. Its prototype is found in /usr/include/mach-o/arch.h.

extern const NXArchInfo *
NXGetLocalArchInfo(void);

NXGetLocalArchInfo returns a NXArchInfo struct.

typedef struct {
const char *name;
cpu_type_t cputype;
cpu_subtype_t cpusubtype;
enum NXByteOrder byteorder;
const char *description;
} NXArchInfo;

Here is some REALbasic sample code that calls NXGetLocalArchInfo and reads the data in the struct.

 soft declare function NXGetLocalArchInfo lib "System.framework" () as Ptr
  
  dim NXArchInfo as Ptr = NXGetLocalArchInfo()
  if NXArchInfo = nil then
    //something went wrong
  end if
  
  dim name as String = NXArchInfo.CString(0)
  dim cputype as Integer = NXArchInfo.Int32(4)
  dim cpusubtype as Integer = NXArchInfo.Int32(8)
  dim byteorder as Integer = NXArchInfo.Int32(12)
  dim description as String = NXArchInfo.CString(16)

Iinterpretation of the numeric fields can be found in /usr/include/nano mach/machine.h.

Comment [3]

---

Older Newer