-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAsciiToBase64.fmfn
60 lines (52 loc) · 1.89 KB
/
AsciiToBase64.fmfn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
------------------------------------------------------------------------------
Purpose: Converts ASCII text to base64 text
Author: J. Michael Tritchler
Notes: This function was developed as part of importing and
exporting the contents of an ASCII text file stored
in a container field
Parameters:
text - ASCII text to be converted to base64 text
Data Type Returned:
text
Variables:
$$base64 - The converted base64 text
~return - Returns the base64 text representation of ASCII text
Depends On:
AsciiToBin ( text )
BinToBase64 ( text )
Revision:
Last change: 24/03/2017 by JMT
::
24/03/2017 - JMT - Wrote original script
------------------------------------------------------------------------------
*/
Let (
[
// Add the newline characters if to each line after the first line has
// been converted to base64
$$base64 = $$base64 & If ( IsEmpty ( $$base64 ) ; "" ; "¶¶" ) ;
// Convert the current 57 ASCII characters to base64 and add it to the
// existing base64 encoded text
// 57 characters are used because it converts to the 76 characters of
// base64 encoded text that filemaker inserts per line in the
// Base64Encode() function
$$base64 = $$base64 & BinToBase64 ( AsciiToBin ( Left ( text ; 57 ) ) ) ;
// Save the base64 text as a local variable so that the global
// variable can be cleared before exiting the function
~return = $$base64
];
If ( Length ( text ) - 57 >= 1 ;
// Convert the next set of ASCII characters to base64 if
// not at the end of the ASCII text
AsciiToBase64 ( Right ( text ; Length ( text ) - 57 ) ) ;
// Clear the global variables and return the base64 text
// as there is no more text to convert
Let(
[
$$base64 = ""
];
~return
)
)
)